I am dynamically generating a list of multiple checkboxes via php.
<input type=\"checkbox\" name=\"quetext[]\" value=".$row_all_que['id'].">
The button which will post the data to php is disabled in the beginning.
<input type="button" value="Next" class="btn btn-primary btn-lg btn-block" id="send-que" disabled>
I want it to enable when at least one checkbox is checked. How will I do that?
Also, once I am done selecting the required checkboxes, I need to create an array of these checkboxes and pass their value to php.
Edit 1:
Since the data was coming from my server via ajax call, the checkbox elements were getting generated dynamically due to which the code that i had written inside document.ready() was not getting executed. I shifted my code into the 'success' function of the ajax call and the button enable/disable on checking the checkbox is working fine now.
Here's the jquery code snippet for the ajax call I made:
$.ajax({
type: "POST",
url: "ajaxData.php",
data: data,
success: function(data) {
$('.quedata').html(data);
var checkboxes = $('.quedata .ques-box');
checkboxes.change(function(){
$('#send-que').prop('disabled', !checkboxes.is(":checked"));
});
}
});
Here the 'quedata' class is my tbody element inside which the checkboxes are getting generated.
This is the HTML structure:
<table class="table table-striped" style="margin-top: 50px;">
<thead>
<tr>
<th>ID</th>
<th>Question</th>
<th>Mark(s)</th>
<th><input type="checkbox" disabled></th>
</tr>
</thead>
<tbody class="quedata">
</tbody>
</table>
Edit 2: Solved
Including the code inside the success part of my ajax call solved it and I am getting my desired output. I have posted an answer including the code.