My HTML form is clearing automatically after I click the submit button. Any idea how to stop this from happening?
Here's the opening tag for the form:
<form onsubmit="return math()">
My HTML form is clearing automatically after I click the submit button. Any idea how to stop this from happening?
Here's the opening tag for the form:
<form onsubmit="return math()">
Share
Improve this question
edited Oct 1, 2010 at 0:58
BrunoLM
100k86 gold badges309 silver badges461 bronze badges
asked Oct 1, 2010 at 0:44
djs22djs22
1,1563 gold badges14 silver badges31 bronze badges
1
- 5 Please show the whole form. I see no code. – Marcus Commented Oct 1, 2010 at 0:46
3 Answers
Reset to default 4One popular approach is to utilize a server-side language such as PHP which reads all the get values and recreates the HTML of the page using a template and substituting in variables.
<input type = "text" name = "Textbox1" id = "Textbox1" value = "{$_GET[Textbox1]}"/>
I've written it out as $_GET directly, but you'd really want to make sure the value was scrubbed so you don't get arbitrary html injection.
A little bit more plicated you could approach this purely client side and utilize javascript to parse the address bar and extract the values submitted to your page (assuming it wasn't submitted with POST as the method). Then you can dynamically repopulate the fields client side.
when you click submit the page refreshes. You'll probably need to return a page with the value of the forms set to what was in when it was submitted.
If math() returns false your data won't disappear but it won't sent data to the server either. If you want to send data to the server you could make a XMLHttpRequest.