Dave's Brain

Browse - Programming Tips - How simulate a user changing their choice for a select in jQuery?

Date: 2010jul7
Library: jQuery
Language: javaScript
Keywords: fire

Q.  How simulate a user changing their choice for a <select> in jQuery?

A.  This is only useful if you have a function to that reacts.

// make your function mySelectChanged() execute when the user // changes the <select> $('.myselect').change(mySelectChanged); // Later in the code, whenever you want it do this // to simulate the user making the change. Your function will execute. $('.myselect').trigger('change');
This works for other types of input too. Like <input type=checkbox> etc

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.