chalpert
chalpert

Reputation: 252

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 '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!

Upvotes: 0

Views: 400

Answers (1)

Adam
Adam

Reputation: 44929

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(); })

Upvotes: 1

Related Questions