mondsteigen
01-16-2012, 12:32 AM
I wrote js functions to reset a php form (multiple questions). The below works:
function resetForm(){
resetGroup(document.forms[0].answer1);
resetGroup(document.forms[0].answer2);
}
Answer1 and answer2 are the elements of $_POST array. (<input name="answer1"> in php). In this example, I tried with only two questions, but I have up to 35 questions in one form. Instead of writing the above resetGroup() 35 times, I want to for-loop it. I tried
function resetForm(){
for (var i=1; i<3; i++){
resetGroup(document.forms[0]."answer"+i);
}
That didn't work. Could someone help me to make the loop work? Or would someone have better or simpler idea? Thanks.
function resetForm(){
resetGroup(document.forms[0].answer1);
resetGroup(document.forms[0].answer2);
}
Answer1 and answer2 are the elements of $_POST array. (<input name="answer1"> in php). In this example, I tried with only two questions, but I have up to 35 questions in one form. Instead of writing the above resetGroup() 35 times, I want to for-loop it. I tried
function resetForm(){
for (var i=1; i<3; i++){
resetGroup(document.forms[0]."answer"+i);
}
That didn't work. Could someone help me to make the loop work? Or would someone have better or simpler idea? Thanks.