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.

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

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();

Comments

Your Answer

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.