Reputation: 149
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.
Upvotes: 0
Views: 3516
Reputation: 104785
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)">
Upvotes: 1