user3049033
user3049033

Reputation: 59

How to move the cursor into a input text box by clicking on html button?

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

Upvotes: 5

Views: 29224

Answers (3)

Rokin
Rokin

Reputation: 41

Try this:

document.getElementById("textbox").focus();

Upvotes: 3

Geo
Geo

Reputation: 12996

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/

Upvotes: 2

عثمان غني
عثمان غني

Reputation: 2708

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();

Upvotes: 1

Related Questions