5

Hi Can anybody tell me How to move the cursor into a input text box by clicking on html button ?

user3049033
  • 59
  • 1
  • 1
  • 4

3 Answers3

3

Try this:

document.getElementById("textbox").focus();
ProGM
  • 6,383
  • 4
  • 28
  • 49
Rokin
  • 41
  • 4
2

HTML:

<input type="text" id="my_textbox" value="My Text" />
<button id="my_button">Focus</button>

JS:

document.getElementById('my_button').onclick = function() {
    document.getElementById('my_textbox').focus();
};

Example:

http://jsfiddle.net/GeoForce/ZnVH7/

Geo
  • 11,580
  • 4
  • 31
  • 54
1

You can just do it by using jQuery as follows:

Include jquery in HTML HEAD section then

$( "#button" ).click(function() {
$( "#targetinput" ).focus();
});

Or without jquery you can do it using

getElementByID("targetinput").focus();
عثمان غني
  • 2,636
  • 4
  • 46
  • 76