SOLVED: form - How to reset
Moderator: General Moderators
-
mondsteigen
- Forum Newbie
- Posts: 17
- Joined: Sat Jan 14, 2012 9:59 pm
SOLVED: form - How to reset
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?
Last edited by mondsteigen on Sun Feb 12, 2012 10:02 pm, edited 2 times in total.
Re: form - How to reset
Hi,If u want to reset the form use this
instead of
Code: Select all
<input type="reset" name="Reset" value="Reset">'.Hope it helps...<input type="submit" name="Reset" onclick="resetForm();" value="Reset">'
-
mondsteigen
- Forum Newbie
- Posts: 17
- Joined: Sat Jan 14, 2012 9:59 pm
Re: form - How to reset
No, that doesn't work in php!
- Tiancris
- Forum Commoner
- Posts: 39
- Joined: Sun Jan 08, 2012 9:54 pm
- Location: Mar del Plata, Argentina
Re: form - How to reset
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!
[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.
[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.
-
mondsteigen
- Forum Newbie
- Posts: 17
- Joined: Sat Jan 14, 2012 9:59 pm
Re: form - How to reset
Thanks a million!!! You gave me a great start of the night!