How can I link this html button to the input type "text" so that when I press enter from the input type, the button is activated? -


here html code form:

<form>  input twitter id: <input type="text" name="userid" id="userid">    <button type="button" onclick="getstatuses();">get recent tweets</button>    </form>  

currently button activates getstatuses(). want when user presses enter/return after inputting text, activates button. input used in getstatuses() , referenced id of input.

you can use onkeyup attribute , call function:

js:

function checkkey(e){     var enterkey = 13;     if (e.which == enterkey){         getstatuses();     } } 

html:

<input type="text" name="userid" id="userid" onkeyup="checkkey(event)"> 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -