I have a JQuery code I have been using for some time however today I ran into a roadblock – this roadblock comes in the form of an array input.
<div id="primary"> //oopse this one contains the survey info
<input type="radio" name="quest[]" value="yes"> //was typing fast didnt realize i typed checkbox meant radio
<input type="radio" name="quest[]" value="no">
</div>
<div id="idnum"> // this one shows only if yes is selected
blah blah blah
</div>
So the inputs are sending to query[]
the logical thing to me says to not use an array – however this is not an option.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#quest[] selected").change(function (e) {
if ($(this).val() == "Yes") { //if query[] = Yes then run following
$("#idnum").hide(); //hide div id=idnum
}
else { //if it no longer shows yes then run following
$("#idnum").show(); //show div id=idnum
}
});
});
array[] has other values under this array for other questions also
how do I fix this to focus on a specific input in the array – each div has a different id and I do have the ability to find the array[number] if need be.
sorry fixed some things and annotated a little
I dont know if it is possible but is it possible to find the with a value of “Yes” that is listed in a specific
jsFiddle DEMO
If I understand the question correctly, and you are trying to hide the nearest parent
<div>and hide it, if they select YES.