0

At start on-change checkboxe it sends values to another TextArea but after using Ajax on another combo on the same page, 'CheckAll' code works but individual check/uncheck code does not send values to the textarea. Please help, thanks.

<script type="text/javascript">     // Add 'usr_id's into textarea
async:true;
$(function() {
    $('input').on('change', function() {
        //alert("Akhtar");
        var values = [];
        $('input:checked').each(function() {

            //values.push($(this).parent().text());     //To catch the 'Text' mentioned in <label> tag
            values.push($(this).attr( "value" ));       //To catch the 'Values' of <input> tag
        //  values.push($(this).val());
        });
        $('[name="usr_id"]').val(values.join(','));
    });
});
</script>

<script type="text/javascript">     // check/uncheck All-Checkboxes

$("#checkAll").change(function () {
    $("input:checkbox").prop('checked', $(this).prop("checked"));
});

</script>

<script type="text/javascript">     // Ajax: Selects 'Type-Names' list dynamically as per 'Employee Type' selected
function loadDoc(htmldiv, contentfile) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById(htmldiv).innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", contentfile, true);
  xhttp.send();
}
function getTypeList(type_check){
    var emp_type=type_check;
    //alert("fsd"+type_check);
    loadDoc('type_id','new_messaging1.php?emp_type='+emp_type);
}
function getUserList(type_check){
    var type_id=type_check;
    var emp_type = document.getElementById('employee_type').value;
    //alert(emp_type);
    loadDoc('usr_list','new_messaging2.php?emp_type='+emp_type+'&type_id='+type_id);
}
</script>

<script type="text/javascript">     // check if a 'User/Msg' mentioned (this is also a code-set for checking that the specific text-box is not empty.
function ValidateRequiredFields()
{
    var message = new String('\n-------------------------------------------------\n');
    var flag=new Boolean(1);

    var x = document.getElementById('msg_text').value;
    var y = document.getElementById('usr_id').value;
    //alert(x+' - '+y);

    message += '   CHECK YOUR VALUES...!';
    message += '\n   No \'message\' typed or no \'user\' selected.';
    message += '\n-------------------------------------------------\n';

    if (x==null || x=="" || y==null || y==""){
        //message += '\n------------------------------------------\n';
        //message += '\nNo \'message\' typed or no \'user\' selected.\n\n\n';
        flag = new Boolean(0);
    }

    if (flag == false){
        if(event.preventDefault){
            event.preventDefault();
        }else{
            event.returnValue = false; // for IE as dont support preventDefault;
        }
        alert(message);
    }

    return flag;
}
</script>

<?php   //The file that is accessed by Ajax
    session_start();
    $flddirectorypath="../";
    include_once("../adminclude/adminc.php");

    $emp_type = $_GET['emp_type'];
    $type_id = $_GET['type_id'];

    $records=$users->selectUsers_Specific($emp_type, $type_id);
    //$records=$users->fillCombo_MyUsers($emp_type, $type_id);

    foreach($records as $record){
                    //$ids=$record["comp_id"];
                    $arrKeys = array_keys($record);
                    $ids=$record[$arrKeys[0]];
?>
                    <label><input type="checkbox" name="usrs" value="<?php echo $ids;?>" /><?php echo $record['usr_fullname'];?></label><br />
                <?php } ?>

EDITED HERE... :

I am using jQuery version: jquery-1.12.0

The links of solutions given by in comments or someone marked it as Duplicate with some link, all do not solve my problem.

Please provide a straight forward modified code. I have not too much know-how to jQuery to modify the code myself. Please tell where and what change should I make in the code of 'onchange' checkbox etc.

Will be grateful to the supporter...

asif
  • 177
  • 1
  • 14
  • You are replacing the elements with your ajax call. So you have to either rebind the event handlers or use event delegation. – Musa Mar 01 '16 at 18:34
  • Please tell a straight forward instruction to modify the code. I have not too much know how to jQuery to handle the code myself. Please tell where and what change should I make in the code of 'onchange' checkbox. – asif Mar 02 '16 at 13:25

0 Answers0