Take the 2-minute tour ×

i'm having a widget with a search-textbox. when pressing enter in it, search starts.

i now want to trigger that enter key by code. in other words, i want to send the enter-keystroke to the textbox.

how does it work?


share|improve this question

2 Answers 2

up vote 3 down vote accepted

I would advise that you trigger the search rather than triggering the keystroke. Obviously, that can be done just by calling the client-side search code or, if searching takes place server-side, submitting the form with the correct arguments/values.

share|improve this answer

Set the onKeyUp event for the input. Get the event key code and if the keycode is enter, then append it to your box. Would look something like this:

function checkEnter(e) {
     if (checkKey(e) == 13) {

function checkKey(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (e.keyCode) {
    	keynum = e.keyCode;
    } else if (e.which) {
    	keynum = e.which;
    return keynum;

<input type="textbox" id="something" onkeyup="checkEnter(event)">
share|improve this answer

Your Answer


