SOLVED: form - How to reset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mondsteigen
Forum Newbie
Posts: 17
Joined: Sat Jan 14, 2012 9:59 pm

SOLVED: form - How to reset

Post 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?
Last edited by mondsteigen on Sun Feb 12, 2012 10:02 pm, edited 2 times in total.
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: form - How to reset

Post 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...
mondsteigen
Forum Newbie
Posts: 17
Joined: Sat Jan 14, 2012 9:59 pm

Re: form - How to reset

Post by mondsteigen »

No, that doesn't work in php!
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

Re: form - How to reset

Post 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. :)
mondsteigen
Forum Newbie
Posts: 17
Joined: Sat Jan 14, 2012 9:59 pm

Re: form - How to reset

Post by mondsteigen »

Thanks a million!!! You gave me a great start of the night!
Post Reply