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 8596023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:34:44+00:00 2026-06-12T00:34:44+00:00

This is probably a very simple question but I can’t seem to get this

  • 0

This is probably a very simple question but I can’t seem to get this right.

Is it possible to extract a variable “name” from a FORM? I have the following pull-down menus (Simplified)…

<FORM NAME="doc_select">
    <SELECT ID="rec_list"  NAME="rec_info"><OPTION>...</OPTION></SELECT>
    <SELECT ID="term_list" NAME="term_info"><OPTION>...</OPTION></SELECT>
    <SELECT ID="comp_list" NAME="comp_info"><OPTION>...</OPTION></SELECT>
</FORM>

These all trigger a bit of java-script via an “onChange” statement. So far so good.

I want to extract the name, not the value, and then use that extracted name in
a java-script statement like below:

var info = form.*name*.value; 

getElementsByName gives me the value not the name.

Any ideas?

Cheers
Frank

  • 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-06-12T00:34:45+00:00Added an answer on June 12, 2026 at 12:34 am

    It’s not clear to me what your issue is, so here’s some general stuff. To get the name of the element that called the listener, pass this:

    <select id="rec_list"  name="rec_info" onchange="someFn(this)" ... >
    

    You can do much the same with a dynamically added listener. In the function:

    function someFn(element) {
      var elementName = element.name;
      var theForm = element.form;
      var theValue = element.value;
    
      // and so on ...
    
    }
    

    You can also access form controls as properties of the form using their name, so once you have a reference to the form:

    form.comp_info
    

    is the third select element in the OP. Note that in this particular case, if there is one control with that name, a reference to the element is returned. If there is more than one control with the same name, a collection is returned. Note also that IE confuses name and id tokens, so never use the same value for the name of one control and the id of another.

    The getElementsByName method returns a collection, the members can be accessed by index so the first one would be:

    var someElement = document.getElementsByName('foo')[0];
    

    Note that if there are no elements with a name of ‘foo’ then someElement will have a value of undefined.

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

Sidebar

Related Questions

I know this is probably a very simple question, but I can't seem to
This is probably a very simple question so please forgive my ignorance, but can
There is probably a very simple answer to this question, but I can't for
This is probably a very stupid math question, but i can't seem to figure
This is probably a very simple question, but I can't find the answer, so
This is probably one very simple question to answer, but I can't output the
This is probably a very simple question, but I just can't figure it out.
This is probably a very simple question but I'm a little confused how this
I know this is probably a very simple question but how would I do
This is another probably very simple question, but I haven't been able to find

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.