Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Hi Can anybody tell me How to move the cursor into a input text box by clicking on html button ?
Try this:
document.getElementById("textbox").focus();
Add a comment
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/
You can just do it by using jQuery as follows:
jQuery
Include jquery in HTML HEAD section then
jquery
HTML HEAD
$( "#button" ).click(function() { $( "#targetinput" ).focus(); });
Or without jquery you can do it using
getElementByID("targetinput").focus();
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.