0

Here is the html code for the form:

<form>
 Input Twitter ID: <input type="text" name="userid" id="userid">  

<button type="button" onClick="getStatuses();">Get recent tweets</button>  

</form> 

Currently the button activates getStatuses(). I want it so that when the user presses enter/return after inputting text, it also activates the button. The input is used in getStatuses() and is referenced by the id of the input.

user1835504
  • 149
  • 2
  • 12
  • possible duplicate of [Trigger a button click with JavaScript on the Enter key in a text box](http://stackoverflow.com/questions/155188/trigger-a-button-click-with-javascript-on-the-enter-key-in-a-text-box) – Shikiryu Apr 08 '13 at 20:10

1 Answers1

1

You can use the onkeyup attribute and call a function:

JS:

function checkKey(e){
    var enterKey = 13;
    if (e.which == enterKey){
        getStatuses();
    }
}

HTML:

<input type="text" name="userid" id="userid" onkeyup="checkKey(event)">
tymeJV
  • 103,943
  • 14
  • 161
  • 157