lundi 27 mars 2017

php/html input checkbox's

Not that sure if this question has been answered somewhere.. have searched for it and found some stuff about it.. but sincerelly don't really understand the answers ive seen and probably am making a major confusion since im not that experienced on working with these languages..

The thing is that i have a group of 5 checkbox's which i want to post in a binary output for example: [0,0,1,1,0].

So far i've managed this by applying the hidden input solution (which i described in a more static way.. since i have a lot of things coming from the db, and other things that dont make sence to explain for this problem.. i think)

$checkychecky = [1,0,1,0,0];
<input type="hidden" name="'.$row_perguntas[0].'[]" value="0"><input type="checkbox" onclick="this.previousSibling.value=1-this.previousSibling.value"'.$checked = ($checkychecky[0] == 1 ? "checked=\"checked\" " : "")/>'.$questionV[1].'

row_perguntas-> comes from the db which gives me the display name

checkychecky -> temp var which stores the values present in the values array [1,0,1,0,0]

questionV -> db label content

which is working just fine.. the problem is when i go forward to another form, and then come back to this form, i get the right arrray values, managed to place the visible checkbox checked, but aint sure on what to do with the hidden field.. since tecnically it isnt set, i dont press the checkbox.. so the onclick doesnt fire.. and when i advance to the next form again i end submiting [0,0,0,0,0]

How should i address this stituation? have tryed to use the.. checkychecky on the hidden input:

<input type="hidden" name="'.$row_perguntas[0].'[]" value="0"'.$value= ($checkychecky[0] == 1 ? "value=\"0\" " : "1")

but no success at all :(

Any ideas? Thanks




Aucun commentaire:

Enregistrer un commentaire