I have a jsfiddle here: http://jsfiddle.net/ybZvv/61/
Please follow steps in fiddle:
- When you open fiddle, click on “Add Question” button twice, this will append 2 rows.
- In first row select answer buttons “A” and “C”, in second row select answer buttons “A”, “B” and “E”. The checkbox values for each answer button selected is displayed underneath.
The problem is though is the structure when I do a var_dump($_POST).
The current structure of the var_dump($_POST) looks like this:
array(3) {
["numQuestion"]=> array(2) {
[0]=> string(1) "1"
[1]=> string(1) "2"
}
["submitDetails"]=> string(14) "Submit Details"
["value"]=> array(4) {
["answerARow"]=> string(2) "on"
["answerCRow"]=> string(2) "on"
["answerBRow"]=> string(2) "on" ["answerERow"]=> string(2) "on"
}
}
I want it to look like below:
array(3) {
["numQuestion"]=> array(2) {
[0]=> string(1) "1"
[1]=> string(1) "2"
}
["submitDetails"]=> string(14) "Submit Details"
["value"]=> array(5) {
[1]=> array(2) {
[0]=> string(1) "A"
[1]=> string(1) "C"
}
[2]=> array(3) {
[0]=> string(1) "A"
[1]=> string(1) "B"
[2]=> string(1) "E"
}
}
}
Does anyone have any ideas on how the code can be manipulated in order to reach this structure?
Virtually what the structure should look like is that there are 2 questions, for question 1 the answers are A and C, for question 2 the answers are A,B and E
Instead of generating
value[answerCRow]in your checkboxes, try to create them as:where, your value will be iterating.
The jQuery’s
updateAnswerfunction will have this line: