D
David Groom
I have a form which contains amongst other code:
<form action="" name="diagform" id="diagform">
<input name="answer" type="hidden" id="q1" value="">
<input name="answer" type="hidden" id="q2" value="">
<input name="answer" type="hidden" id="q3" value="">
........
<input name="answer" type="hidden" id="q9" value="">
<form>
and I have the following javascript function:
function SetAnswer(quest,ans) {
var quest,ans;
document.diagform.answer[quest].value=quest+'.'+ans;
}
This works as I expect it, that is to say that when SetAnswer is called as
SetAnswer(q1,1) the value of answer gets set to 1 for the first hidden
field,etc.
However when the form is submitted I want all the values of answer to be in
an array for processing in PHP.
To do that I have to change the input names to "answer[]".
I can't now work out how to set the value of that element using javascript.
Anyone got any ideas?
<form action="" name="diagform" id="diagform">
<input name="answer" type="hidden" id="q1" value="">
<input name="answer" type="hidden" id="q2" value="">
<input name="answer" type="hidden" id="q3" value="">
........
<input name="answer" type="hidden" id="q9" value="">
<form>
and I have the following javascript function:
function SetAnswer(quest,ans) {
var quest,ans;
document.diagform.answer[quest].value=quest+'.'+ans;
}
This works as I expect it, that is to say that when SetAnswer is called as
SetAnswer(q1,1) the value of answer gets set to 1 for the first hidden
field,etc.
However when the form is submitted I want all the values of answer to be in
an array for processing in PHP.
To do that I have to change the input names to "answer[]".
I can't now work out how to set the value of that element using javascript.
Anyone got any ideas?