Here's a tricky one to start the morning.
I have a series of icons. When you click an icon it loads a form. Some of the forms have input[text] others have textareas.
What I'm trying to come up with is jQuery that once I load the form I can run that will... Focus in on the first input or textarea whatever it may be, dynamically so I don't need if blocks.
Ideas?
Just in case you want to focus on the first element in a form, here is how to do it through one simple jQuery sector: $('#form-id :input:enabled:visible:first'). focus();
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.
Answer: Use the jQuery . focus() method focus() method to set the focus on the first input box or textarea inside the Bootstrap modal when it is loaded upon activation.
tab, shift + tab and enter key and focus should be trapped inside modal and should not go out after pressing tab key multiple times.
This should do it I think
$("#formId input:text, #formId textarea").first().focus();
Here it is:
$('#form-id :input:enabled:visible:first').focus();
#form-id is ID of the form; :input selects any input and textarea element; :enabled ensures the input is editable; :viisble ensures that the element is visible; :first is obvious
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With