Reputation: 189
I am trying to store multidimensional array, taken from an HTML form, into javascript array.
I have this simple form:
<label for="radek_predpisu_1">První řádek předpisu</label>
<input type="text" name="predpisy[text][]" id="text_predpisu_1" value="" maxlength="100" size="60" title="Text předpisu" placeholder="Text předpisu" class="text ui-widget-content ui-corner-all">
<input type="text" name="predpisy[cena][]" id="cena_predpisu_1" value="" maxlength="4" size="4" title="Cena bez DPH" placeholder="Cena bez DPH" class="text ui-widget-content ui-corner-all">
<input type="text" name="predpisy[pocet][]" id="pocet_predpisu_1" value="" maxlength="4" size="4" title="Počet jednotek" placeholder="Počet jednotek" class="text ui-widget-content ui-corner-all">
Now I use:
var predpisy = $('[name="predpisy"]');
What should I do next? If I try to alert( predpisy['text'][0]
and I got undefined
.
Thank you very much.
Radek
Upvotes: 0
Views: 1035
Reputation: 2244
var predpisy = $('[name^="predpisy"]');
console.log(predpisy[0]['text']);
console.log(predpisy[0]['cena']);
console.log(predpisy[0]['pocet']);
Upvotes: 0
Reputation: 4521
$('[name="predpisy"]')
is only going to give you elements whose name exactly matches the string 'predpisy'.
What you want is this: $('[name*="predpisy"]')
, which will select all elements whose name contains 'predpisy', which I think is what you're looking for.
Upvotes: 2