The change event is triggered by the field receiving focus, changing value from whatever the defaultValue was, and then losing focus. Maybe you could step through those events within the function that's currently only changing the picker.

Or use a synthetic event, and have onchange on the picker set to fire it along with your change function. Then you only need one piece of code to observe the synthetic event.

document.observe('my:event',function(){ /*do something here*/ });

select id="myCars" onchange="$(this).fire('my:event');"

function foo(){
        $('myCars').setValue('audi').fire('my:event');
}

Walter

On Jun 23, 2010, at 8:24 AM, Hari wrote:

Hi,

I have simple select box

<select id="myCars">
 <option value="volvo">Volvo</option>
 <option value="audi">Audi</option>
</select>

and my Javascript

$('myCars').observe('change', doSomething);

function doSomething(){
 alert('doSomething');
}

In My code I want to programatically select "audi"... for which i do

$('myCars').value="audi";     // also tried other options like making
options selection true

This changes the selection in UI but doesn't trigger the onChange
event.
How can I fire the on change event programatically.

Thanks and Regards
Hari

--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com . To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en .


--
You received this message because you are subscribed to the Google Groups "Prototype 
& script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to