I have multiple input tags in a form, and I need to prepare all values to be send through an Ajax request. Here is an example of input fields :
<form>
<input name="foo" value="1">
<input name="foo1" value="1">
<input name="bar[]" value="2">
<input name="bar[]" value="2">
<input name="fooBar[a][]" value="3">
<input name="foobar[b][]" value="3">
</form>
Expected result :
{
foo : "1",
foo1 : "1",
bar : ["2", "2"],
fooBar : { a : ["3"], b : ["3"]}
}
or :
{
foo : "1",
foo1 : "1",
"bar[0]" : "2",
"bar[1]" : "2",
"fooBar[a][0]" : "3",
"fooBar[b][0]" : "3"
}
I have no idea on how and where to start building my function, so maybe anyone has an idea and can give me a hint on how this may be done in plain javascript.