Sorry if this is extremely obvious, but I have looked and looked for a solution but haven't found anything. I'm very new to jQuery, so even looking for what I want to do has been hard.
I have a page with a bunch of fields and drop down boxes that are populated from a database. So each drop down has the correct item (the one stored in the database) selected when the page loads. When that option is "Other" I want my Other text box to show up.
So, the question is; how do I show/hide that text box based on the selected drop down item when the page loads? Everything I have been able to find in my research has been related to the drop down menu changing. This works fine for one of the other pages I have. I don't want to have to reselect "Other" (triggering the change event).
Thanks
$(function() {
if($("#yourDropDown").val() == 0) //I'm supposing the "Other" option value is 0.
$("#yourTextBox").hide();
});
$("option").bind('click', function(){
var selected = $(this).val();
alert(selected+' selected');
if (selected == '1') { /* do anything you want */ }
if (selected == '2') { /* do anything you want */ }
//etc ...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With