I have this simple html table, where each cell has a input field
<table>
<tbody>
<tr>
<td>
<input type="text"name="bezeichnung" value="Bezeichnung" />
<br />
<textarea value="Beschreibung" name="beschreibung"></textarea>
</td>
<td><input type="text" name="menge" value="0,00" /></td>
<td><input type="text" name="einheit" value="Stk." /></td>
<td><input type="text" name="preis" value="0,00 €" /></td>
<td><input type="text" name="gesamt" value="0,00 €" readonly /></td>
</tr>
</tbody>
</table>
Now I would like to get all values into an jQuery array. I tried this:
function getAllValues() {
var allValues = {};
$("#table tbody tr").find("input").each(function( index ) {
params[index] = $(this).val()
})
console.log(params)
}
Output
{0: "Test", 1: "My Description", 2: "2,00", 3: "Fahrt", 4: "10,00 €", 5: "20,00 €"}
This looks okay, but not good. Instead of the index key 0, 1, 2, ... I would like to have the attribute "name" of the input field. But I don't know how :/
And the next problem is if I have more than one row the output looks like this:
{0: "Test", 1: "My Description", 2: "2,00", 3: "Fahrt", 4: "10,00 €", 5: "20,00 €", 6: "Test 2", 7: "", 8: "1,00", 9: "Std.", …}
It will be a long array instead of multidimensional array. Have you any idea?
Thank you very much !