jQuery onchange of one drop down displays another drop down
I have 2 drop downs. one hidden and one displayed on the s开发者_StackOverflowcreen. During onchange of one drop down the second drop down is displayed. But I need to do validations like, the customer must have chosen one value from the 2nd drop down instead of the default one. I used jquery to fetch the second drop down using it's id attr. example: where addresses is the form id, and this method will be invoked for all the select elements in the form.
jQuery('#addresses select').change(function() {
form_validations(jQuery(this));
});
The problem is on change of the second drop down this method is not getting invoked.
I presume this is because, when the page is initially loaded the second drop down is not available. Can someone help?
this is already answered question, please check out this answer
How can I populate another dropdown with the onChange event of the first dropdown?
this will make you helpful,
Thanks.
Normally you would use .live() or .delegate() method to bind events to future elements, but the change() event might not be supported.
Your best bet would be to bind the event when you create the second 'select' element.
update: you can use .live()/.delegate() with change
try this:
$('select').live('change', function() {
form_validations($(this));
});
精彩评论