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
imrealashu
5,0994 gold badges18 silver badges28 bronze badges
-
1An object id should be always unique!Reporter– Reporter2014年07月14日 14:25:07 +00:00Commented Jul 14, 2014 at 14:25
2 Answers 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());
});
answered Jul 14, 2014 at 14:22
Kiran
20.3k11 gold badges72 silver badges101 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Amit Joki
59.4k7 gold badges80 silver badges97 bronze badges
Comments
lang-js