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

  • SEARCH
  • Home
  • 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 4031018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:32:42+00:00 2026-05-20T11:32:42+00:00

This is driving me nuts, and I’m sure it’s both possible and surely simple

  • 0

This is driving me nuts, and I’m sure it’s both possible and surely simple to do.

I have a page with a whole bunch of dynamically created forms on it. In one of my functions, I need to access one of those forms, so I pass the name of the form in a variable.

Then I need to access the name of that form using the document tree.

However, when I put in the variable, it assumes the name of the variable is the name of the form.

So this does not work:

function myAwesomeFunction(nameOfForm)
{
 var selection = document.nameOfForm.nameOfInput.selectedIndex;
}

So I looked around the net and saw that I need to use bracket notation, but this doesn’t work either:

function myAwesomeFunction(nameOfForm)
{
 var selection = document[nameOfForm].nameOfInput.selectedIndex;
}

I also tried with some quotation action:

function myAwesomeFunction(nameOfForm)
{
 var selection = document['nameOfForm'].nameOfInput.selectedIndex;
}

… but no joy.

So, where am I going wrong?

For bonus points… what if both the name of the form and the name of the particular input were both dynamic? Then what?

function myAwesomeFunction(nameOfForm, nameOfInput)
{
 var selection = document[nameOfForm][nameOfInput].selectedIndex;
}
  • 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-20T11:32:42+00:00Added an answer on May 20, 2026 at 11:32 am

    Look them up in the forms object – this won’t work since it is an array and not an object.

    use document.getElementsByName

    function myAwesomeFunction(nameOfForm, nameOfInput)
    {
     var selection = document.getElementsByName(nameOfForm)[nameOfInput].selectedIndex;
    }
    

    or even better, set an id attribuite on the form and use document.getElementById to find the form

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NHibernate is driving me 'Nuts'!!! I have the following mapping. Which returns this error
This is driving me nuts. I have been at it for over 2 hours
This is driving me nuts! I have a test instance of Wordpress installed on
This is driving me nuts - I have been round and round in circles,
This is driving me nuts. I have two tables that I am attempting to
This is driving me nuts ;) I have this stored procedure ... ALTER PROCEDURE
This is driving me nuts. I am using some 3rd-party code in a Windows
Ok, this is driving me nuts. I've done just about everything I can to
This is driving me crazy. I have this one php file on a test
This issue is driving me mad. I have several tables defined, and CRUD stored

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.