Note that there are some explanatory texts on larger screens.

plurals
  1. POReset a form through javascript that is called via php
    text
    copied!<p>Ok I have googled for hours and found nothing that works. I need help desperately</p> <p>I have got a form with the following elements in it.</p> <pre><code>&lt;form action="sendmail.php" method="post" name="enquiry"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Name:-&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="name" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Company:-&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="company" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;E-Mail:-&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Contact:-&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="contact" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Requirement:-&lt;/td&gt; &lt;td&gt;&lt;textarea name="msg"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" value="submit" onclick="return validation(this.form);"&gt; &lt;input type="reset" value="Reset" /&gt; &lt;/form&gt; </code></pre> <p>and the php has a line like this:</p> <pre><code>&lt;?php if(mail($to, $subject,$message)) { echo "&lt;SCRIPT LANGUAGE='JavaScript'&gt;alert('Your Enquiry was sent successfully we will get back to you shortly'); window.location.href='javascript:history.go(-1)'; document.enquiry.reset(); &lt;/SCRIPT&gt;"; } ?&gt; </code></pre> <p>Then there's an "else" with the same code but a different message.</p> <p>The problem is when it redirects back to the form page it still has the data in the fields. What I prefer is a clean form with no data filled in when the user returns to the page.</p> <p>Please note I am a newbie to javascript so try suggesting a fix that would be easy to comprehend.</p> <p>Thanks a lot in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload