Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting focus to a textbox when a function is called

Tags:

People also ask

How do you put a focus on a TextBox in HTML?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.

What is TextBox focus () in C#?

When showing a form that contains a TextBox, it's common courtesy to focus the TextBox so that the user can begin typing immediately. To focus a TextBox when a Windows Form first loads, simply set the TabIndex for the TextBox to zero (or the lowest TabIndex for any Control on the Form).

How do you know if a TextBox has focused?

The hasFocus() method returns a true if the document (or any element in the document) has focus.


I currently have a textbox in my aspx:

 <input type="text" id="myTextbox"  value="" />

I was wondering if I could set the focus (put my cursor in that text box) every time my JavaScript method is called. I was hoping it would work along the lines of this:

function setFocus() {
    document.getElementById("myTextbox").Focus();
}

Any suggestions?