I have been trying to made a form that when radio button no is clicked it will show the text field and when yes is clicked no text will disappear and yes text will show,but not working ?
The form code :
<form>
<label for="Q01">
Question 1:<br/>
<input name="Q01" id="Q1_A02" type="radio" value="Q1_A02" class="more" />No, why?
<input class="more" name="why" id="Q1_A03" type="text" value="" /><br />
<input name="Q01" id="Q1_A04" type="radio" value="Q1_A04" class="mor"/>yes, why?
<input name="why" id="Q1_A05" type="text" value="" /><br />
</label>
The jquery code :
$(document).ready(function() {
$("input[name$='why']").hide();
$("label input[type='radio']").change(function() {
if ($(this).hasClass('more')) $(this).next().show();
else $(this).parent().children("input[type='text']").hide();
if ($(this).hasClass('mor')) $(this).next().show();
else $(this).parent().children("input[type='text']").hide();
});
$("label input[type='checkbox']").change(function() {
if ($(this).hasClass('more')) {
$(this).next().toggle();
}
});
});
Aucun commentaire:
Enregistrer un commentaire