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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:16:21+00:00 2026-05-28T08:16:21+00:00

id = [<input type=​hidden name=​id value=​test_id>​, <input type=​hidden name=​id value=​test_id>​] id.val() Result: test_id I

  • 0
id = [<input type=​"hidden" name=​"id" value=​"test_id">​, <input type=​"hidden" name=​"id" value=​"test_id">​]
id.val()
Result: "test_id"

I have an “id object” with two HTML Elments. There are the same because I will update two identical Elements with one ajax get.

I got this variable “id” with a selector who search for a form.

My Question:

Is .val() checking both Elements or only the first Element in this object “id”?

And what is if one of the Elements has a different value.

What I did after this question!

  • I’m using now .map() to get both values from the objct
  • Added a check for the equality of the id’s.
  • Learned not to skip the first big sentence (Description) on the
    Jquery Docs =)

Thanks a lot!

  • 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-28T08:16:22+00:00Added an answer on May 28, 2026 at 8:16 am

    .val() will check the value of the first element in the set of elements it is run on. If you pass .val() a function like this: .val(function (index, value) {}) then you can get the value for every element in the set of element that the function is run on.

    You might want to check-out the docs for .val(): http://api.jquery.com/val

    $('input').val(function () {
        console.log(this.value);
        return this.value;
    });
    

    Here is a demo: http://jsfiddle.net/mV4U6/2/ (If you change the value of any input then the value of all the inputs will be console.loged)

    As lonesomeday stated, this requires you to return the value so the form element will retain its value. You can however use .map() to get the values of each input:

    $('input').map(function (index, element) {
        console.log(this.value);
    });
    

    Here is a demo using .map(): http://jsfiddle.net/mV4U6/3/

    …Also possible with a loop:

    var $inputs = $('input');
    for (var i = 0, len = $inputs.length; i < len; i++) {
        console.log($inputs[i][0].value);//or inputs[i].val() will also work
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below html code in my aspx. <input type=hidden id=medicalLink value='<a href=/forms/contactus.aspx >Contact
I have the below code in my .aspx page. <input type=hidden id=fbinfo name=fbinfo value=
Which should I use? <input type=hidden name=first_name value=<%= person.first_name %> /> or <input type=hidden
I have an input field whose name is an MD5 string e.g.: <input type=hidden
How can I get rid of: <input type=hidden name=__VIEWSTATE id=__VIEWSTATE value=.../> Completely !
I have an hidden input field with a value, <form> <input type=hidden value=product/> <select
The page I'm trying inspect has a hidden <input type=hidden name=Foo value=123 /> element
$regexp = '/(?:<input\stype=hidden\sname=){1}([a-zA-Z0-9]*)(?:\svalue=1\s\/>)/'; $response = '<input type=hidden name=7d37dddd0eb2c85b8d394ef36b35f54f value=1 />'; preg_match($regexp, $response, $matches); echo
<td valign=top> <input type=hidden name=MAX_FILE_SIZE value=12485760 /> Image?</td> <td><input type=file name=image> $path = uploads/;
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input

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.