开发者

javascript or jquery event that fires whenever the selected value of a select changes

I know i can use the javascript event onchange, or the jquery event change, however, enother of these cover the senario when the user does not change the value of the select him self.

For example, when using javascripts onchange event if I have three cascading selects and I select the first one, and the second one populates and the default value if the second one is the one the user wants, the onchange event 开发者_如何学JAVAof the second select is never fired, hence the third select is never populated.

ideas?


two ways you can do

1> on second <select> create first option with value= "[choose something]" this way user will be forced to choose some thing from select2

2> When you populate the second select ,trigger its onchange event


How about putting a dummy value at the beginning on the select ,like a blank option. So that the user is forced to select another that has a value.


Insert a dummy item in the second select as the first item:

<option value="">-- select one --<option>

That way the user must fire the change event to select an item,


Autopopulate the third select box with the values it should have for the default of the second is one option. Otherwise as others have suggested a Please Choose option that forces onchange to fire.


If your changing the content via javascript, you can also trigger the change event explicitly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜