With check boxes if none is checked nothing is passed. If you have a value then at least one checkbox was checked.
May 31, 2020
2
Level 5
identify atleast one checkbox is checked in array of checkbox with multiple div
iam working with a project online examination quiz
my code
@foreach($assessments->assessmentsubdetails as $question)
<div id="questions{{ $loop->iteration }}" name="questions[]">
question description
<input type="checkbox" name="stud_answer{{ $loop->iteration }}[]" id="A" value="A">
<input type="checkbox" name="stud_answer{{ $loop->iteration }}[]" id="B" value="B">
<input type="checkbox" name="stud_answer{{ $loop->iteration }}[]" id="C" value="C">
<input type="checkbox" name="stud_answer{{ $loop->iteration }}[]" id="D" value="D">
</div>
@endforeach
i have question list in side
<ul class="all-option">
@foreach($assessments->assessmentsubdetails as $question)
<li><a href="#questions{{ $loop->iteration }}" class="smoothScroll">{{$loop->iteration}}</a></li>
@endforeach
</ul>
if one option from 1st question is checked the class="smoothScroll" must changed to class="SmoothScroll green" like this the question list must change.
but only once. that is if only one check box from each question only.
what i tried in my JS is
var questions = document.getElementsByName('questions[]');
here whats my problem is questions1, questions2.. like this the class name and id changes based question
var chkboxx = document.getElementsByName('stud_answer[]');
here whats my problem is stud_answer1, stud_answer2.. like this the class name and id changes based question
for (var i = 1; i < questions.length; i++) {
var chkboxx = document.getElementsByName('stud_answer' + [i] + '[]');
alert(i);
if (chkboxx[i].is(':checked')) {
alert("s");
alert("checked");
} else {
alert("notchecked");
}
}
how i can iterate and check if a checkbox from specifc question is checked or not, kindly some one help please
Please or to participate in this conversation.