2

I have some input fields like this

<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>
<input id="serial" type="text" name="serialname" class="serialclass"/>

I want to get values from all the input fields using jQuery and store it into a array.

asked Jul 14, 2014 at 14:20
1
  • 1
    An object id should be always unique! Commented Jul 14, 2014 at 14:25

2 Answers 2

2

Id's should be unique across DOM. So change your id's and use class to get all input values and push it to array.Try this:

var arr = [];
$("input.serialclass").each(function(){
 arr.push($(this).val());
});

DEMO

answered Jul 14, 2014 at 14:22
Sign up to request clarification or add additional context in comments.

Comments

2

First ids have to be unique.

Answer:

var arr = $('.serialclass').map(function(){
 return this.value;
}).get();
RevanProdigalKnight
1,3261 gold badge14 silver badges23 bronze badges
answered Jul 14, 2014 at 14:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.