Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript form validation still redirects
    primarykey
    data
    text
    <p>For some reason, this code always redirects to education.php regardless of whether or not the fields are blank. I want to verify the fields have values in them, but for some reason they keep redirecting but not writing anything in the database. Any help would be greatly appreciated.</p> <pre><code>&lt;body&gt; &lt;form action="education.php" method="post" onsubmit="return validate_fields()"&gt; &lt;div style="text-align: right"&gt; &lt;ul&gt; First Name: &lt;input id="first_name" name="first_name" size=25/&gt; &lt;br&gt; Last Name: &lt;input id="last_name" name="last_name" size=25/&gt; &lt;br&gt; Email: &lt;input id="emailaddress" name="emailaddress" size=25/&gt; &lt;br&gt; Password: &lt;input id="user_password" name="user_password" type="password" size=25/&gt; &lt;br&gt; &lt;center&gt;&lt;input type="submit" name="submit" id="submit" value="Register Now"/&gt;&lt;/center&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; function validate_fields() { var first_name = document.getElementByID("first_name").value; var last_name = document.getElementById("last_name").value; alert(""+first_name+" "+last_name); if (first_name.length &lt; 1 || last_name.length &lt; 1) { alert("Please fill in your name."); return false; } var email = document.getElementById("emailaddress").value; if (email.length &lt; 1) { alert("Please fill in your email address."); return false; } var password = document.getElementById("password").value; if (email.length &lt; 1) { alert("Please put in a password."); return false; } alert(first_name+" "+last_name+" "+email); return false; //was true, changed to see if still redirects. } &lt;/script&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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