Send checked table row value in array

I have a table like this:

CheckBox    Course    Semester   Paper       Level
  []         ABC         1         1     •Expert •normal
  []         ABC         1         2     •Expert •normal
  []         ABC         1         3     •Expert •normal

 [Save]

In the above table checkbox value is paper value. The trouble i am having is that , when i click on save, it runs a parameterised javascript function addpapers($course,$semester) as you can see they are same, but i am not able to send the checkbox value and level value together. a person can choose either expert or normal level for a given paper. I am not able to send them in javascript.

  • Get random item for array based on different probabilities?
  • Can I pass an array into fromCharCode
  • How to force a blank space in a text array?
  • Javascript unset array
  • JQuery .each() backwards
  • When looping through values of a JS array, and I remove value, do I need to use while instead of for?
  • function flagaddpapers(course, semester) {
        displayBox = document.getElementById("studentBox");
        elements = document.getElementsByName('pids[]');
        levelid = document.getElementsByName('radios[]');
    
        data = [];
        for (i = 0; i < elements.length; i++) {
            if (elements[i].checked) {
                data.push('pids[]=' + encodeURIComponent(elements[i].value));
            }
        }
        params = "teacher=" + encodeURIComponent(teacher) + "&course=" + encodeURIComponent(course) + "&semester=" + encodeURIComponent(semester) + "&flag=" + encodeURIComponent(1) + "&" + data.join('&');
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.body.removeChild(document.getElementById('loadMsg'));
                result = xmlhttp.responseText;
                alert(result);
                displayBox.className = "dimBox";
                setTimeout(function () {
                    ajaxstp();
                    document.body.removeChild(document.getElementById('adBackground'));
                    document.body.removeChild(document.getElementById('adBox'));
                }, 200);
            }
        }
        xmlhttp.open("POST", "tpaper.php", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send(params);
    }
    

    This is my html code:

    echo "<tr>
    <th style='font-size:12px;'><input type='checkbox' id='master_check'
    onclick='masterSelect();' style='display:inline-block;cursor:pointer;'></th>
    <th style='font-size:12px;'>S.No</th>
    <th style='font-size:12px;'>Course</th>
    <th style='font-size:12px;'>Semester</th>
    <th style='font-size:12px;'>Level</th>
    <th style='font-size:12px;'>Paper</th></tr>";
    $counter17 = 1;
    while($row4 = mysql_fetch_array($q4))
    {
    $pids = $row4['pid'];
    echo "<tr>";
    echo "<td><input type='checkbox' name='pids[]' class='persistentChecks'
    style='display:inline-block;cursor:pointer;' value=".$pids."></td>";
    echo "<td style='text-align:center;font-size:12px;'>".$counter17."</td>";
    echo "<td style='text-align:center;font-size:12px;'>".$row4['cname']."</td>";
    echo "<td style='text-align:center;font-size:12px;'>".$semester."</td>";
    echo "<td style='font-size:12px;'><input type='radio' name='radio[]' id='radio1'
    value='1'>Expert</input><input id='radio2' type='radio' name='radio[]' 
    value='2'>Normal</input></td>";
    echo "<td style='text-align:center;font-size:12px;'>".$row4['pname']."</td></tr>";
    $counter17 = $counter17 + 1;
    }
    echo "</table>";
    echo "<div style='text-align:left;'><input type='button' class='t_s' value='Add Paper'
    onclick='flagaddpapers(".$course.",".$semester."); return false'
    id='addpaperBtn'><input type='button' class='t_s' value='Cancel' onclick='closedialog();
    return false'></div>";
    

  • finding the biggest difference between sorted array values
  • create new element from array until array is empty every second
  • Build tree array from flat array in javascript
  • Get an object in array by one of its fields
  • Why does my reduce based average function return NaN?
  • Join nested array
  • One Solution collect form web for “Send checked table row value in array”

    Try this..
    here pval is the paperid and lval is the level value

    <script type="text/javascript">
    function merge_value(lval,pval)
    {
    document.getElementById(pval).value=pval + '-' + lval;
    }
    </script>
    
    <?php
    
    echo "<tr>
    <th style='font-size:12px;'><input type='checkbox' id='master_check'
    onclick='masterSelect();' style='display:inline-block;cursor:pointer;'></th>
    <th style='font-size:12px;'>S.No</th>
    <th style='font-size:12px;'>Course</th>
    <th style='font-size:12px;'>Semester</th>
    <th style='font-size:12px;'>Level</th>
    <th style='font-size:12px;'>Paper</th></tr>";
    $counter17 = 1;
    while($row4 = mysql_fetch_array($q4))
    {
    $pids = $row4['pid'];
    echo "<tr>";
    echo "<td><input type='checkbox' name='pids[]' id='".$pids."' class='persistentChecks'
    style='display:inline-block;cursor:pointer;' value=".$pids."></td>";
    echo "<td style='text-align:center;font-size:12px;'>".$counter17."</td>";
    echo "<td style='text-align:center;font-size:12px;'>".$row4['cname']."</td>";
    echo "<td style='text-align:center;font-size:12px;'>".$semester."</td>";
    echo "<td style='font-size:12px;'><input type='radio' name='radio[]' id='radio1'
    value='1' onClick='javascript:merge_value(this.value,".$pids.")'>Expert</input><input id='radio2' type='radio' name='radio[]' 
    value='2' onClick='javascript:merge_value(this.value,".$pids.")'>Normal</input></td>";
    echo "<td style='text-align:center;font-size:12px;'>".$row4['pname']."</td></tr>";
    $counter17 = $counter17 + 1;
    }
    echo "</table>";
    echo "<div style='text-align:left;'><input type='button' class='t_s' value='Add Paper'
    onclick='flagaddpapers(".$course.",".$semester."); return false'
    id='addpaperBtn'><input type='button' class='t_s' value='Cancel' onclick='closedialog();
    return false'></div>";
    
    ?>