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

The Archive Base Latest Questions

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

I have a form like this <form id=myform> <input type=hidden name=a value=a1/> <input type=hidden

  • 0

I have a form like this

<form id="myform">
<input type="hidden" name="a" value="a1"/>
<input type="hidden" name="b" value="b2"/>
<select name="c"><option value="c3" selected="true"/></select>
<input type="text" name="d" value="d4"/>
</form>

Now, I want to get list of all input and select elements in the form

  var mydata = new Array();
  $('#myform').find('input, select').each(function ()
  {
    mydata.push($(this).val());
  });

Result I am getting is: a1, b2, d4, c3
But what I want to get is: a1,b2,c3,d4 (in the same sequence as displayed in UI).

Note: I can give some dummy class (say: mydatafields) to all the input and select elements and use:

$('mydatafields').forEach()

something like, but I am checking if there is a better solution.

Thanks in advance.

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

    The most efficient way is by adding a temporary attribute (e.g class name) to your elements, then loop through each element, and finally remove it.

    var mydata = [];
    $('#myform').find('input, select').addClass('temporaryClassName');
    $('.temporaryClassName').each(function() {
        mydata.push($(this).val());
    }).removeClass('temporaryClassName');
    

    An alternative method consists of selecting ever input element using :input, and filter the desired elements. For this example, filtering is not strictly needed. I have included the line for educative purposes.

    var mydata = [];
    $('#myform').find('input, select').each(function() {
        if(!/^input|select$/i.test(this.nodeName)) return; //Filter non-input/select
        mydata.push($(this).val());
    });
    alert(mydata)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this: <form id='myForm'> <input type='text' name='Textbox'> <select name='SelectBox'>
For example I have a form like this: <form method='post' action='someaction.php' name='myform'> <input type='text'
I have a form like this: <form id='myForm'> <input type='text' name='search' /> <input type='text'
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
Suppose I have a form like this: <form id='myform'> Favorite colors? <input type='checkbox' name='color'
i have this form: <form name=myForm action=#> <input type=text name=firstField /> <input type=text name=secondField
If I have some hidden inputs in my form: <input type=hidden name=test value=somedata> <input
I have a form like this: <form action=search.php class='search' method='GET'> <input type=text/submit class=home_search_area value=Search
If I have a form like this . <form name=myform action= method=POST> <select name=mydropdown>

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.