Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me how I can able to set the focus on a text box using JavaScript? Herewith I have attached my query:

<script>

  function setFocusToTextBox(){

    //What to do here

  }

</script>

Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

Depending on the element which you have used, you can use the below code:

<script>

function setFocusToTextBox(){

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

}

</script>

I hope this will help.

Want to become a Java Expert? Join Java Certification now!!

Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...