Page 1 of 1

SOLVED: form - How to reset

Posted: Sat Jan 14, 2012 10:57 pm
by mondsteigen
I've written a multiple-choice test. Everything works except the reset button after submission. I've tried unset($_POST), but it did not reset the form to its original state (ie.,before the submit button was clicked). Could someone help me?

Re: form - How to reset

Posted: Sun Jan 15, 2012 2:48 am
by Gopesh
Hi,If u want to reset the form use this

Code: Select all

<input type="reset" name="Reset" value="Reset">'
instead of
<input type="submit" name="Reset" onclick="resetForm();" value="Reset">'
.Hope it helps...

Re: form - How to reset

Posted: Sun Jan 15, 2012 8:27 am
by mondsteigen
No, that doesn't work in php!

Re: form - How to reset

Posted: Sun Jan 15, 2012 9:22 am
by Tiancris
The Reset button returns the form to state that it had when the page was loaded. There is no way that a page can know what was his state in the previous load. So, Javascript is the only answer! :P

[text]<script type="text/javascript">
function resetGroup(group) {
var i = 0;
while (group != null) {
group.checked = false;
i++;
}
}
function resetForm(){
resetGroup(document.forms[0].answer1);
resetGroup(document.forms[0].answer2);
}
</script>[/text]

It is based on the fact that a group of radios can be explored as an array, and then setting checked = false to uncheck them. It also works for groups of checkboxes. :)

Re: form - How to reset

Posted: Sun Jan 15, 2012 10:58 am
by mondsteigen
Thanks a million!!! You gave me a great start of the night!