Problems with submit button reloading page when there is an if...else statement.
Hey guys, I have a form that I perform some AJAX business on when it is submitted. However, I wanted to have an if...else statement but when I add it it allows the page to refresh upon submit. For example...
- $(document).ready(function() {
- // register form onsubmit function
- $('#register_form').submit(function() {
-
- // declare variables
- var input_email; input_email = $("#register_form_input_email").val();
- // verify email
- $.post("emailverifier.php", { email: input_email },
- function(data) {
- if (data.valid == 1) {
- // display ok
- $("#register_form_span_email").html("Ok!");
- } else {
- // display error
- $("#register_form_span_email").html("Error!");
- }
- }, "json"
- );
- return false;// stop form from refreshing the page
-
- });
-
- }); // end document ready
Works properly, but...
- $(document).ready(function() {
- // register form onsubmit function
- $('#register_form').submit(function() {
-
- // declare variables
- var input_email; input_email = $("#register_form_input_email").val();
- // verify email
- $.post("emailverifier.php", { email: input_email },
- function(data) {
- if (data.valid == 1) {
- // display ok
- $("#register_form_span_email").html("Ok!");
- } else {
- // display error
- $("#register_form_span_email").html("Error!");
- }
- }, "json"
- );
- if (1=1) {
- alert("One indeed equals one!");
- } else {
- alert("What the...?!?");
- }
- return false;// stop form from refreshing the page
-
- });
-
- }); // end document ready
Allows the page to refresh.
I'm reasonably new to jQuery and JavaScript so I'm hoping that there is a simple explanation for this. Can anyone tell me why this is?
Neilos