Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a keypress trigger using JQuery

Tags:

html

jquery

How do i send a trigger keypress of a particular keyCode eg. "9" event on a TextBox using JQuery programmatically?

This what i intend to do; Programmatically enter a value to a TextBox and then programmatically trigger a tabkey on the TextBox to exit the field.

my code

$("#tags1").val("comp") // Works well

$("#tags1").trigger("keypress",[9]); // Fails!!

Gath

like image 723
gath Avatar asked Apr 30 '09 14:04

gath


1 Answers

The jQuery documents state that it'll only pass normalized event attributes = the properties of the jQuery.Event object, which don't seem to include event-specific data.

I tried, and couldn't get it to insert text into a textbox even when reusing an event object that a browser keypress created, so it doesn't seem to be possible.

Why can't you just change the value of the textbox, and call blur() to exit it? (Or focus() on the one you want to enter next?)

like image 87
millimoose Avatar answered Oct 06 '22 01:10

millimoose