Hey Ya\'ll I have got a question with my radio buttons I have these 3 buttons
No
$('input[name=answer]').change(function(){
if(this.value) == 'yes'{
$('#otherAnswer').show();
}else{
$('#otherAnswer').hide();
}
})
While the answers above are sufficient if you're keen on using jquery/ javascript, this can be very easily achieved using just CSS. Try it on Codepen.
#otherAnswer {
display: none;
}
#other:checked ~ #otherAnswer {
display: flex;
}
<div>
No<input type="radio" id="no" name="answer" checked="checked" value="no"/>
Yes<input type="radio" id="yes" name="answer" value="yes"/>
Other<input type="radio" id="other" name="answer" value="other"/>
<input type="text" id="otherAnswer" name="otherAnswer"/>
</div>
$(":radio").on('click',function (){
if ($(this).is(":checked") && $(this).val()=='other') ) $('#otherAnswer').show(); else $('#otherAnswer').hide();
});
I think this is more effective.
$("input[name='answer']").change(function(){
if($(this).val() == "yes")
{
$("#otherAnswer").show();
}else{
$("#otherAnswer").hide();
}
});
$("input[type='radio']").change(function(){
if($(this).val()=="other")
{
$("#otherAnswer").show();
}
else
{
$("#otherAnswer").hide();
}
});
Here is the working example : http://jsfiddle.net/Wc2GS/8/