Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set focus on first field of input in BootStrap? [duplicate]

Possible Duplicate:
How to set the focus to the first input element in an HTML form independent from the id?

I'm using BootStrap with ASP.NET MVC4. There is one login form but I'm unable to set focus on first input field.

How to set focus on first field of input? Is there any BootStrap class that uses to set focus?

like image 556
Dharmik Bhandari Avatar asked Jan 17 '13 12:01

Dharmik Bhandari


People also ask

How to set focus on input field or textarea inside bootstrap modal?

How to set focus on input field or textarea inside a Bootstrap modal on activation. Answer: Use the jQuery .focus() method. You can use the jQuery .focus() method to set focus on the first input box or textarea inside the Bootstrap modal when its load upon activation, like this: Example. $(this).find('#inputName').focus();

Is there any bootstrap class that uses to set focus?

Is there any BootStrap class that uses to set focus? There isn't a Bootstrap-specific class or function that does this*, but HTML5 provides the autofocus attribute for input fields. This attribute currently enjoys wide browser support.

How do I change the focus of a form in Bootstrap?

Answer: Use the CSS box-shadow Property By default, all the textual <input> elements, <textarea>, and <select> elements with the class.form-control highlighted in blue glow upon receiving the focus in Bootstrap. However, you can modify this default focus glow or shadow styles by simply setting the CSS border-color and box-shadow property.

How do you focus an input field in JavaScript?

The onload event executes a function that finds the input field with the firstField ID via document.getElementById and then uses the JavaScript focus () method to set the state of the input field to focus. Does the focus outline disappear from your input field all of a sudden?


1 Answers

There isn't a Bootstrap-specific class or function that does this*, but HTML5 provides the autofocus attribute for input fields.

This attribute currently enjoys wide browser support.

*-Since you are using Bootsrap, and Bootstrap is powered by jQuery, you could "shim" older browsers that otherwise don't support autofocus:

$('[autofocus]:first').focus();
like image 93
Jeromy French Avatar answered Oct 19 '22 10:10

Jeromy French