Hi I am fairly basic in jQuery, and got stuck in a script:
//hide all radio buttons first
$('#q11_6_1').parent().hide();
$('#q11_6_2').parent().hide();
$('#q11_6_3').parent().hide();
$('#q11_6_4').parent().hide();
$('#q11_6_5').parent().hide();
//check the length of the open text box
var other2text = $('#q11_6_other').val().length;
$('#q11_6_other').keypress(function(){
//if at least one character has been entered, then I want to show all radio buttons
if(other2text>=0)
{
$('#q11_6_1').parent().show();
$('#q11_6_2').parent().show();
$('#q11_6_3').parent().show();
$('#q11_6_4').parent().show();
$('#q11_6_5').parent().show();
}
//else I want to hide all
else
{
$('#q11_6_1').parent().hide();
$('#q11_6_2').parent().hide();
$('#q11_6_3').parent().hide();
$('#q11_6_4').parent().hide();
$('#q11_6_5').parent().hide();
}
});
The first part of the “if condition” is working, however when I have cleared all texts in q11_6_other, those radio buttons won’t hide. I think the “else” section is not working, but not sure how to get around it.
Much appreciated with your help!!!
Put your variable
other2textinside the event hander function:Also, I suggest you use
keyupinstead ofkeypress. If you do that however, you need to changeother2text>=0toother2text>0