jeudi 28 juillet 2016

How to check the boolean of checkbox?

I know this might sounds duplicate questions but none of them work for me. So far that i have done is getting the value but i want to know how to get the on/off value from the checkbox. I tried hidden field but i can't get the 1/0 value from the checkbox itself. All i get is the value.

My code is like this

$(document).delegate('.sBorrow', 'change', function(){
            var sBorrowClass = $(this).attr('class');
            var sBorrowValue = $(this).attr('value');
            var sBorrowName = $(this).attr('name');

            if(sBorrowClass.checked = true){
                alert(sBorrowValue);
                alert("unchecked");
            }
            else{
                alert(sBorrowValue);
                alert(sBorrowClass);
            }

For the checkbox form is like this

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'] ."'>
            <input type='hidden' name='sBorrow' value=0 />
            </form></td></tr>";
            $startrow++;
            //echo $row['education_level'];

and questions 2.. Also how to make my checkbox remains checked when the user searching for more data after check the checkbox (Livesearch Ajax). Should i use localStorage or SESSION to store the value up until the user refresh?




Aucun commentaire:

Enregistrer un commentaire