0

While i tried to get json data from html inputs i found this thread: Convert form data to JavaScript object with jQuery

The serializeObject function does most of the things I need, there is only one thing I haven't got done yet

I have 4 characters and to each of them the user can assign 0 to 3 points

So the json I get is

{"charakter1":"0","charakter2":"2","charakter3":"3","charakter4":"1"}

But i would like save this information as array, so what i want is

{"charakter":[0,2,3,1]}

How do i have to change the name of the radio buttons to get this array?

I created a jsfiddle for this http://jsfiddle.net/sxGtM/3028/

Community
  • 1
  • 1
obs
  • 797
  • 3
  • 14
  • 37

1 Answers1

1

Try using arrays for the variables, like this:

<input type="radio" name="charakter[2]" value="0"/>0
<input type="radio" name="charakter[2]" value="1" checked />1
<input type="radio" name="charakter[2]" value="2"/>2
<input type="radio" name="charakter[2]" value="3"/>3<br/>

<input type="radio" name="charakter[3]" value="0"/>0
<input type="radio" name="charakter[3]" value="1" checked />1
<input type="radio" name="charakter[3]" value="2"/>2
<input type="radio" name="charakter[3]" value="3"/>3<br/>

Results in this:

{"charakter":["0","2","3","1"]}

jFiddle is here: http://jsfiddle.net/sxGtM/3029/

showdev
  • 28,454
  • 37
  • 55
  • 73