Change select box options
I have two select boxes, the second of which is populated once the first has been chosen. Currently I use $('#category').live('change', function() { }); which changes the 2nd box after the user has made changes to the first.
The problem is, if I load a default value into the first box, the 2nd box isn't populated because the 开发者_JS百科'change' event never occurs. How would I modify the script so that the 2nd box is populated based on the content of the first box? Thanks!
Make the function a separate named function
function populateSecond(){ }
$('#category').live('change', populateSecond);
then run it once when the page first loads so that the second <select>
is poplulated from the value the first one has on page load
$(document).ready(function(){ populateSecond(); })
精彩评论