Hello friends I have a drop down box with yes and no values. By default it's set to 'No' however when we select the value of yes another div should appear. Please help
+2
A:
$('#IdOfYourDropDown').change(function(){
if($(this).val() == 'Yes'){
$('#IdOfYourDiv').show();
}
else{
$('#IdOfYourDiv').hide();
}
});
Patricia
2010-08-24 13:47:16
and without jquery? :PI'd type out an answer but I don't think the asker will accept any answer anyway
Litso
2010-08-24 13:53:44
@Litso: I guess the 'without jQuery' has like no interesst to the OP, only tagging `jQuery`.
jAndy
2010-08-24 13:59:13
the question was tagged jQuery... so i gave a jQuery answer :)
Patricia
2010-08-24 14:59:35
@patricia @jAndy haha, didn't notice that. Sorry :P
Litso
2010-08-24 19:02:46
@Litso: ahhh so it was you who downvoted my answer?
Patricia
2010-08-24 19:37:39
A:
$('#my_dropdown_id').bind('change', function(){
switch($(this).val().toLowerCase()){
case 'yes':{
$('#my_show_id').show();
break;
}
case 'no':{
$('#my_show_id').hide();
break;
}
}
});
You can extend that switch statement with any other value you might want to test for.
jAndy
2010-08-24 13:49:02
A:
Thank you patricia, very much appreceated. I don't know how to accept answer, pls anyone suggest me. The javascript version would be great for learning purpose but too much code i guess. Thanks
sagarmatha
2010-08-24 21:21:49