simulating an change event jquery

Raphaël picture Raphaël · Nov 10, 2011 · Viewed 7.3k times · Source

I have five lists (select) that are populated with php / mysql and jquery. I use this script: http://bit.ly/3YTAXe

When I post my form and the new page appears, I redisplay my five list and I want my 5 lists will populate with the values ​​posted.

I think I'd have to simulate the event "change" or something like that. I do not think my code can help (it's inside the smarty and many other things).

Does anyone can help me from the example code that is in the link above?

Answer

Andy picture Andy · Nov 10, 2011

try .trigger()

$('#yourselect').val('yourvalue');
$('#yourselect').trigger('change');

It can also be chained into a single statement:

$('#yourselect').val('yourvalue').trigger('change');