Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  163] [ 6]  / answers: 1 / hits: 18645  / 11 Years ago, tue, january 14, 2014, 12:00:00

I would like to automatically add the selected value when enter key is pressed on chosen jquery single select. So, for that is there any event like keypress which I would use to do something when return key was pressed?



<select id=myselect data-placeholder=Add foods you can buy here. 
style=height:30px; width: 100% class=chosen-select onkeypress=handle(event) >
<option value=></option>
<optgroup label=blah>
<option>blah blah</option>
</optgroup>
</select>

More From » jquery

 Answers
69

Bind the keyup event on the jquery chosen dropdown, after chosen in initialized.



Depending upon the version either you need to use .chosen-container or .chzn-container.



$(.chosen-select).chosen({});

$(.chosen-container).bind('keyup',function(e) {
if(e.which === 13) {
$('#myform').submit();
// or your stuff here...
}
});

[#73186] Monday, January 13, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ernest

Total Points: 332
Total Questions: 92
Total Answers: 98

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;