开发者

Preserve onchange for a dropdown list when setting the value with Javascript

I have a dropdown list with a piece of code that is run when the value is changed:

<select name="SList" onchange="javascript:setTimeout('__doPostBack(\'SList\',\'\')', 0)" id="SList">

Everything works fine when manually done. As an option is selected, the onchange code is called.

The problem begins when I try to change the selected value using a piece of Javscrip开发者_StackOverflowt. I want to be able to automatically change the selected option using JS, whilst still having the onchange code called, exactly as if done manually.

I try calling this:

form.SList.value = "33";

The right option is selected, but the onchange code does not get called. So then I try doing this:

form.SList.value = "33";
javascript:setTimeout('__doPostBack(\'SList\',\'\')', 0);

The right value is not selected and nothing happens.

FYI, the code is done in ASP.NET and Javascript.

What can I run to change the selected option whilst still calling the onchange code?


try

form.SList.value = "33";
__doPostBack('SList','');

instead.

The javascript:myfunction tag is just for in-HTML use.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜