mercredi 27 juillet 2016

How to get value of checkbox from PHP and DOM

i need to know how on earth to get my checkbox value from PHP that is in a loop and also might be in DOM. I have to put that checkbox inside the loop to make it being shown on each row of databases. I tried to call it back using different method but none success. The last part is javascript but i don't have any clue how to do that.

My code for javascript index.php.

 function ajaxSearchUpdater(p){
        $("#result").show();
        var x = $("#search").val();
        var y = $("#edulevel").val();
        var pagelim = $("#pagefpe").val();
        var pagenumber = p;
        var checkb = $(".sBorrow").val()
        $.ajax({
            type:'POST',
            url:'userres.php',
            data:'q='+x+'&e='+y+'&pagelim='+pagelim+'&pageno='+pagenumber+'&checkb='+checkb,
            cache:false,
            success:function(data){
                $("#result").html(data)
            }
        });
    }



    $(document).ready(function(e) {
        ajaxSearchUpdater(1);               // fires on document.ready
        $("#search").keyup(function() {
            ajaxSearchUpdater(1);           // your function call
        });
        $("#edulevel").click(function() {
            ajaxSearchUpdater(1);           // your function call
        });
        $("#pagefpe").click(function() {
            ajaxSearchUpdater(1);           // your function call
        });
        $('.sBorrow').on('change', function(){
            var checkBorrow = $(event.target);
            var isChecked = $(checkBorrow).is(':checked');
            alert("test");
            alert(isChecked);
            alert('checkbox'+checkborrow.attr('id')+'is checked:'+isChecked);
        });
    });

    $(document).ready(function() {
      $('.sBorrow').on('change', function(event) {
        var checkbox = $(event.target);
        var isChecked = $(checkbox).is(':checked');
        alert('checkbox ' + checkbox.attr('id') + ' is checked: ' + isChecked);
      });
});

My code for the checkbox in PHP userres.php

if($stmt->rowCount() > 0){
    $r=$stmt->fetchAll();
    echo "<table class='tablesorter-blackice' id='myTable' style='width:97%; table-border: 1'>";
        echo "<thead>";
        echo "<tr>";
        echo "<th>No.</th>";
        echo "<th>No.Matric</th>";
        echo "<th>Name</th>";
        echo "<th>Programme</th>";
        echo "<th>Title</th>";
        echo "<th>Thesis Level</th>";
        echo "<th>Serial Number</th>";
        echo "<th>Availability</th>";
        echo "<th>Select book (Max 3)</th>";
        echo "</tr>";
        echo "</thead>";
        echo "<tbody>";

    foreach($r as $row){
            $sBorrow = $_SESSION['sBorrow'];

            echo "<tr align='center'><td>". ($startrow+1) ."</td><td>". $row['matricno'] ."</td><td>". $row['studentname'] ."</td><td>". $row['programme'] ."</td><td>". $row['title'] ."</td><td>". $row['thesis_level'] ."</td><td>". $row['serialno'] ."</td><td>". $row['bavailable'] ."</td><td>
            <form method='post'>
            <input type='checkbox' name='sBorrow' id='sBorrow' class='sBorrow' value='". $row['serialno'] ."'>
            </form></td></tr>";
            $startrow++;
            //echo $row['education_level'];
    }
    echo "</tbody>";
    echo "</table>";

I don't know what to do since i'm calling that page from ajax and uhh how should i explain this. You know index.php -> userres.php -> index.php using ajax. for javascript on the bottom part is what i have done and i dont think its right. I tried to create one other document ready for this checkbox but still even alert not showing up. I'm confused. please help T_T




Aucun commentaire:

Enregistrer un commentaire