lundi 17 septembre 2018

checking to see if Checkbox is checked is being skipped during execution

Good evening every one.

I've been racking my brain around this for hours and haven't gotten anywhere. Hopefully one of yall can help me here. I'm a newbie to Jquery so please bare with me. I have a simple form that I will be submitting to a database, after validation and vetting of course.

However, I'm hung up with retrieving the state of the checkbox that I am using. My Code returns all values except for the checkbox and is almost like it is skipping the retrieval of the Checkbox state because the alerts after the variable declaration because the alerts with the other values fire and show.

However the checked property isn't returning anything. I've searched and found countless ways of doing this and I felt like I have tried all of them. Below is just a few ways I've tried. Can anyone see what I am doing wrong???

my check box element

<input type="checkbox" name="isOnline" class="form- 
control" >

my Java script

$(function(){
    $('#submit').on('click', function() {
              var studId=$('input[name="Selected"]:checked').val();
              var classId=$('#ClassSelection').find(":selected").val();
              var classCode=$('input[name="Code"]').val();
              //var isOnline=$("input[type='checkbox']").val();
              //var isOnline=$("input[name='isOnline']").prop('checked');
              //var isOnline=$("input[name='isOnline']").is('checked');
              var isOnline=$("input[name='isOnline']").val();
              alert(studId);
              alert(classId);
              alert(classCode);
              alert(isOnline);
     });

});      




Aucun commentaire:

Enregistrer un commentaire