Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get javascript to run onsubmit
    text
    copied!<p>Trying to practice some form validation in the shape of an email reset page.</p> <p>Here is my code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; form validation &lt;/title&gt; &lt;script&gt; function validateForm() { var email=document.forms["email_reset"]["user_email"].value; var atpos=email.indexOf("@"); var dotpos=email.indexOf("."); var pass1=document.getElementByID("new_pwd"); var pass2=document.getElementByID("confirm_pwd"); if(atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=email.length) { alert("Your email address is invalid!"); return false; } if(pass1 != pass2) { alert("Your passwords do not match!"); return false; } else { alert("Your password has been succesfully reset!"); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="email_reset" onsubmit="validateForm()"&gt; &lt;br /&gt; &lt;font id="title" face="arial" color="white" size="2"&gt;[ Enter your email and new password below ]&lt;/font&gt;&lt;br /&gt;&lt;br /&gt; &lt;label id="email_lab" color="white"&gt;Email Address:&lt;/label&gt; &lt;input type="text" class="input" name="user_email" id="user_email" maxlength="100" align="right" /&gt;&lt;br /&gt; &lt;label id="newpass_lab" color="white"&gt;New Password:&lt;/label&gt; &lt;input type="password" class="input" name="new_pwd" id="new_pwd" maxlength="64" align="right" /&gt;&lt;br /&gt; &lt;label id="confirmpass_lab" color="white"&gt;Confirm Password:&lt;/label&gt; &lt;input type="password" class="input" name="confirm_pwd" id="confirm_pwd" maxlength="64" align="right" /&gt;&lt;br /&gt; &lt;input style="width: 25%; margin-bottom: 10px;" type="submit" class="input" id="sub_button" value="Submit" /&gt;&lt;br /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I want to have an alert pop-up if the email input doesn't match that of an email format, and if the password inputs aren't identically similar. However when I click submit, I get nothing.</p> <p>I was using <a href="http://www.w3schools.com/js/js_form_validation.asp" rel="nofollow">this</a> tutorial as a guide. I guess somehow I'm still missing something. </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