Timeline for answer to How to get an Array with jQuery, multiple <input> with the same name by Kobi
Current License: CC BY-SA 2.5
Post Revisions
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 8, 2016 at 6:15 | comment | added | Amit Bera | you are genius .. I have do this for select box. | |
| Apr 8, 2015 at 16:14 | comment | added | Normadize |
Be careful with .map(), in some browsers it returns an array but in others it returns an object m.fn.init[] (Chrome). This latter one cannot be stringified by JSON.stringify(). Specifically, the following two are NOT equivalent: var arr=$('input[name="foo"]').map(function(){return this.value}).get() with var arr=[]; $('input[name="foo"]').each(function(){arr.push(this.value)}). In the first case arr is not an Array whereas in the latter case it is. JSON.stringify(arr) fails for the former, but works for the latter.
|
|
| May 8, 2014 at 12:46 | history | rollback | Kobi |
Rollback to Revision 2
|
|
| S May 8, 2014 at 12:33 | history | suggested | Community Bot | CC BY-SA 3.0 |
Please, don't use the same ID multiple times, this is weird.
|
| May 8, 2014 at 12:32 | review | Suggested edits | |||
| S May 8, 2014 at 12:33 | |||||
| Dec 29, 2013 at 10:34 | comment | added | GabAntonelli | it works thanks! I forgot to change the function to alert the content of the array on the screen and it was blocking all the code when submitting! | |
| Dec 29, 2013 at 10:24 | comment | added | GabAntonelli | I can't make it work :( thanks anyway, I'll post a new question | |
| Dec 29, 2013 at 10:04 | comment | added | Kobi |
@Gabz - I'd target their container, something like $('.row').map(function(){var row = $(this); return {name: row.find('.name').val(), surname: row.find('.surname').val()};}).get();, which results in an array of objects, not just values. Feel free to ask a new question with your code if you need additional help. Thanks!
|
|
| Dec 29, 2013 at 9:47 | comment | added | GabAntonelli | how can I do if I want to add for each element of the array, each index [n], another value? Example: <input type="text" class="name" /> <input type="text" class="surname" /> | |
| May 1, 2013 at 4:55 | comment | added | Kobi |
@orrd - $(...) returns an array-like jQuery wrapper. $(...).get() returns a real array of real DOM nodes, not a string.
|
|
| Apr 30, 2013 at 22:46 | comment | added | orrd | The .get() flattens the array of values into a string. If you did want the actual Javascript array of values, you should remove the ".get()". | |
| Apr 30, 2013 at 22:28 | review | Suggested edits | |||
| Apr 30, 2013 at 22:43 | |||||
| Mar 27, 2013 at 8:55 | comment | added | imdahmd |
why do we need .get() for?
|
|
| Apr 13, 2010 at 11:38 | vote | accept | x4tje | ||
| Apr 13, 2010 at 8:12 | comment | added | Kobi |
@x4tje - no problem. You don't have to use explode - note that values is an array, not a string. It depends on how you do your AJAX call, or course.
|
|
| Apr 13, 2010 at 8:10 | vote | accept | x4tje | ||
| Apr 13, 2010 at 11:38 | |||||
| Apr 13, 2010 at 8:10 | comment | added | x4tje | this is working good with the 1,2,3 so i'll use this with the explode function of php to get it sorted thanks @all for helping | |
| Apr 13, 2010 at 7:57 | history | edited | Kobi | CC BY-SA 2.5 |
added 71 characters in body
|
| Apr 13, 2010 at 7:52 | history | answered | Kobi | CC BY-SA 2.5 |