Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add input from user inmidatley to <input>

For this example i have a simple html markup:

<input id="INPUT"/>

What i would like to achieve now is that when the user types something. His input is inmidiatley shown in the #INPUT. I tried this, but somehow it wont work:

$('document').keydown( function(e) {
   $('#INPUT').focus();
});

What should i do instead? Thanks http://jsfiddle.net/GdVvd/

like image 505
John Smith Avatar asked Jan 17 '26 23:01

John Smith


2 Answers

You do not need quotes around document, as the selector will look for element having a tagName matching "document" if you put it in quotes.

Live Demo

$(document).keydown( function(e) {
   $('#INPUT').focus();
});
like image 106
Adil Avatar answered Jan 20 '26 16:01

Adil


A HTML5 solution would be to simply give your input element an autofocus attribute. This will make it focused when the page loads:

<input id="input" autofocus />

JSFiddle demo.

Note however that this solution currently does not work on IE or Firefox.

like image 23
James Donnelly Avatar answered Jan 20 '26 16:01

James Donnelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!