Getting Value Of Multiple Input Fields With Same Class And Adding Into Javascript Object
or If you want values into an array
$('.email').map( function(){return $(this).val(); }).get();
.get()
will convert it to a regular array.
The code you have written is absolutely correct. But when I have loaded it was returning me null, because at the time of execution, there were no values in textboxes.
Solution 2:
Your taskArray
is actually an object, not an array.
Replacing var taskArray = {}
with this should fix the problem:
var taskArray = new Array();
Edit: on second thoughts, what you have already is perfectly valid!
I'm editing my answer to echo what I've said in the comments: you'll need to debug using the console:
Within the .each()
, put: console.log(id);
- the expected result would be "1", "2", "3" - if it's just "3", it probably means that your other inputs aren't being picked up for whatever reason. If that is the result, print out the object after you've assigned the value: console.log(emailObj[id]);
.
Post a Comment for "Getting Value Of Multiple Input Fields With Same Class And Adding Into Javascript Object"