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

The Archive Base Latest Questions

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

I am trying to access each individual element, ie option, defined for a list

  • 0

I am trying to access each individual element, ie option, defined for a list box (or drop down box).

For some reason the code I am using is not working. It is given below—

$(jQuery('input', $(this).parent('form'))).each(function() {
        element= $(this);

            textmsg=" Element # " + (count+1) + "...Name of this input element = " + $(this).attr('name') + " multiplechoice-" +  $(this).attr('multiple');
            textmsg= textmsg + "...Also, for this element, the value is " + $(this).val() + " and type =" +  $(this).attr('type');
            alert (textmsg);
         var listofoptions = new Array();
         type=$(this).attr('type');
         if(type=="select")//this means we have to go through the children for this select element, to obtain the values for each option
         {
             var elements= $('option', this);
             for(var i=0; i<elements.length; i++)
            {
                // add $(this).val() to your list

                alert("Value of this option=" + $elements[i].val()); 
            });

         }
});

How do I make the above code work? Or can you suggest an alternative way of accessing each option value? Thanks…

  • 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:34:01+00:00Added an answer on May 26, 2026 at 5:34 pm

    In order to select all inputs you would need to use the :input selector and not just $('input') as this will select inputs by tag name and the select will be excluded.

    So do

    $(this).parent('form').find(':input')
    

    Also, since there’s no type attribute on a select element. You could use .is() instead to check if it’s a select.

    $(this).is('select') 
    

    Edit: for the if statement i would do the following

    if( $(this).is('select') )
    {
        $(this).find('option').each(function(){ 
           alert( $(this).val() );    
        });            
    }
    

    Here’s a fiddle

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

Sidebar

Related Questions

I am trying to access each element in a List<string> list and split each
I'm trying to create an access control system. Here's a stripped down example of
I'm trying to access each value in a array without serializing it. I than
I'm creating a Windows service and am trying to access some files I added
I have a dictionary list and I want to access the 2nd child element
Im trying to access a web service from a remote computer. I managed to
Im trying to access the Magento customer session in another part of my website.
Im trying to access a Sql CE 2005 database on a windows mobile device
I am trying to access Outlook 2007 from C#. I have installed the PIA
I'm trying to access the Facebook API Admin.getMetrics method via jQuery. I'm correctly composing

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.