views:

721

answers:

3

in one of my selection box, i have a onChange="..." specified... coz i want to change some other form value after any selection changes.

however ... in the same page, some wired case i have to manually set the value.. so i have to use some javascript to set the value of the selection combox, but in this case, i don`t want that onChange event to be fired...

how can i walk around it???

Forgot to mention that i am actually using dijit.form.comboBox. for normal HTML form comboBox, it won`t cause any issue. Only i use the dijit comboBox, and i try to set the value to some other value, dojo will trigger the onChange.

+1  A: 

You don't need to do anything. Setting the value with Javascript will not fire your onchange event handler.

Josh Stodola
yeah..u are right.just i forgot to mention that i am actually using dijit.form.comboBox. for normal HTML form comboBox, it won`t cause any issue. Only i use the dijit comboBox, and i try to set the value to some other value, dojo will trigger the onChange.
shrimpy
+1  A: 

In general, setting the value with JavaScript won't fire onchange. If you're dealing with a strange browser that does fire it, you could remove the onChange (element.onchange = null), change the value, then add it back (element.onchange = functionname) afterwards.

Zarel
Forgot to mention that i am actually using dijit.form.comboBox. for normal HTML form comboBox, it won`t cause any issue. Only i use the dijit comboBox, and i try to set the value to some other value, dojo will trigger the onChange.Thanks for your quick answer
shrimpy
A: 

FYI, this answer is not fully correct. It is true that simply setting the value does not trigger the onChange event, BUT as soon as the control loses focus, the change will be detected and onChange will be fired.

So delaying onChange is not really the same as preventing onChange - which is what I need to do!

I could temporarily remove the event, blur and refocus the field, and then restore the event, but this is an ugly hack. It is complicated by dynamicaly added events like jQuery. so really what I'd like is to set the 'focus value' to the 'new value', but haven't been able to find this. I could try setting the defaultValue, but this would prevent a correct form.reset().

Kevin

related questions