Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:57:46+00:00 2026-05-26T17:57:46+00:00

Dynamically created form contains input elements. First elements may be disabled or readonly. I

  • 0

Dynamically created form contains input elements. First elements may be disabled or readonly.
I tired code below to set focus to first elemnt which accepts data to enable fast data enttry form keyboard.
However if form fist element is disable or readonly, focus is not set.
How to set focus to first element which accepts data ?

    <form style='margin: 30px' id="Form" class='form-fields' method='post' target='_blank'
    action='Report/Render'>
...
    <input id='_submit' type='submit' value='Show report' class='button blue bigrounded' />
    </form>
    <script type="text/javascript">
        $(function () {
            var elements = $('#Form').find(':text,:radio,:checkbox,select,textarea');
            elements[0].focus();
            elements[0].select();
});
</script>

Update

There are also hidden input fields, sorry. Answers provided set focus to hidden element. Answr containing function does not find any element.ˇ

Here is the update testcase:

$(function () {
  $("#form :input:not([readonly='readonly']):not([disabled='disabled'])").first() 
                                                                        .focus(); 
});

How to set focus to vist visible, enabled and not readonly element ?

Update 3

I tried Row W code where input element was added.
Now it sets focus to second element. Testcase is shown at Revision 5 of Rob W’s answer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:57:47+00:00Added an answer on May 26, 2026 at 5:57 pm

    Use the following code:

    var elements = $('#Form').find(':text,:radio,:checkbox,select,textarea').filter(function(){
        return !this.readOnly &&
               !this.disabled &&
               $(this).parentsUntil('form', 'div').css('display') != "none";
    });
    elements.focus().select();
    

    If you only want to select the first element, the following code is more efficient:

    $('#Form').find(':text,:radio,:checkbox,select,textarea').each(function(){
        if(!this.readOnly && !this.disabled &&
                    $(this).parentsUntil('form', 'div').css('display') != "none") {
            this.focus();  //Dom method
            this.select(); //Dom method
            return false;
        }
    });
    

    Update: if you want to have the elements in the same order, use:

    var elements = $("#form").find("*").filter(function(){
       if(/^select|textarea|input$/i.test(this.tagName)) { //not-null
           //Optionally, filter the same elements as above
           if(/^input$/i.test(this.tagName) && !/^checkbox|radio|text$/i.test(this.type)){
               // Not the right input element
               return false;
           }
           return !this.readOnly &&
                  !this.disabled &&
                  $(this).parentsUntil('form', 'div').css('display') != "none";
       }
       return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to drag and drop the dynamically created controls my code is shown below
I have a form with dynamically created input fields - upon submitting it I
How to handle dynamically generated form submit in asp.net mvc? Form is dynamically created
What is the simplest way to dynamically create a hidden input form field using
I have a screen where the formBase contains all of the dynamically created UI
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
I have dynamically created a xml string form a JSON object returned from server.
I've got a form that's dynamically created using ajax (as data for the form
I have dynamically created TValueListEditor VCL component on a TForm . The code is
I have a form that is dynamically created. It is a winForms application. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.