1

I am working on a chained select menu, which you can see here - http://jsfiddle.net/stocktrader/EhUKJ/. I have it coded so that the "country" selection changes the "state/zip/city" options via show/hide. All of that is working well.

But my problems is that this form is also used for updating this information for each person. And when I populate the form with current data, I can't get the correct show/hide settings to trigger based on the country setting. You can see an example in the current fiddle where I pre-selected "United States", but the "city/state/zip" options don't come up. The DO come up if you click to a different country and then back on.

I attempted to write some JavaScript that would change the populated show/hide settings by retrieving the "country" value but I don't know JavaScript at all. I tried the below code, which is in the fiddle, but I doubt it is even close.

var s = document.getElementById('country');
var item1 = s.options[s.selectedIndex].value;
function cty()
{
    if (item1 == 'group1')
    unhide('.group1_opts');
}
4

1 回答 1

0

When you bind a function to any of the event handlers in jQuery - simply calling the handler a second time without a parameter will trigger it's execution.

Eg. $('select').change(); will run the "change group" function you applied to it - In this case any "pre-selected" options will be processed.

updated your fiddle

于 2013-03-30T10:16:25.003 回答