View Full Version : [RESOLVED] Resetting a form when submitting
Parashurama
02-07-2008, 04:27 PM
Hi.
I'm trying to clear a contact-form when when the user has pushed the submit button. Anyone know how to do this?
The reason I want this is because a new window opens and tells the user that the message has been sent. And when this window is closed the message is still in the form.
Hope i make myself clear :)
Parashurama
rangana
02-07-2008, 07:40 PM
Hi parashurama,
Try putting this script:
function clear_form()
{
document.login.reset();
}
Now, on your form, just add an OnSubmit attribute, like:
OnSubmit="setTimeout('clear_form()', 200); return true"
Where 200 means .2 milliseconds.
You could also set this on page load.
See if it helps. :D
Parashurama
02-08-2008, 01:42 PM
what language is the function? PHP or javasript?
I also have this :
onsubmit="window.open('about:blank','foo','height=150,width=300');"
How would i incorpurate your code? Just with a : ","?
rangana
02-08-2008, 07:52 PM
That is a javascript!...and by the way!...
onsubmit="window.open('about:blank','foo','height=150,width=300');"
This one is also a javascript!..This opens a blank window having height of 150 and width of 300.
What's the purpose of opening a blank window after submit??...
If it has nothing to do, then just replace your onSubmit with
OnSubmit="setTimeout('clear_form()', 200); return true"
Just put this script in the <head> section:
<script type="javascript">
function clear_form(){
document.login.reset();}
</script>
See if it helps:D
Parashurama
02-10-2008, 01:14 PM
Hmmm... It did not work. It did not clear the form :(
biggnigg
02-10-2008, 05:35 PM
well, this is the code that i have in my "onClick" button for a RESET button on my site
onClick="window.location.reload()"
i dont really know off the top of my head how to incorporate that into your submit button
probably use "onClick=" or "onSubmit="
Clueful
02-10-2008, 07:03 PM
Hmmm... It did not work. It did not clear the form :(The moment a form is submitted, the page is unloaded, therefore any pending timeouts cannot execute.
As has been suggested already, you could reset the form on page load, however the data may still be present if the back button is used.
You could try this idea but I haven't tested it.
Have a second hidden form that has the same inputs/action/method as the first.
The onsubmit handler of the visible form should perform these actions:
Copy all its data into the hidden form
Call its own reset method
Call the submit method of the hidden form
Return false (may be superfluous but just in case).
Theoretically the hidden form will be submitted and the visible (now empty) form will not.
Parashurama
02-11-2008, 07:10 PM
thanx for the sugestions, but i figured it out. I usen both a onclick and a onsubmit like this:
<form target="foo" action="mail.php" method="post" onsubmit="reset()", onclick="window.open('about:blank','foo','height=150,width=300')">
Thanx again for leading me in the right direction!
Parashurama
02-11-2008, 07:12 PM
well that did not work :) that made a new window when i mouseclicked on a new field(or anywhere in the form), but this did the trick :)
<form target="foo" action="mail.php" method="post" onsubmit="reset(),window.open('about:blank','foo','height=150,width=300')">
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.