Problems with submit button reloading page when there is an if...else statement.

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...

  1. $(document).ready(function() {

  2. // register form onsubmit function
  3. $('#register_form').submit(function() {
  4. // declare variables
  5.                 var input_email; input_email = $("#register_form_input_email").val();

  6. // verify email
  7.   $.post("emailverifier.php", { email: input_email },
  8. function(data) {
  9. if (data.valid == 1) {
  10. // display ok
  11. $("#register_form_span_email").html("Ok!");
  12. } else {
  13. // display error
  14. $("#register_form_span_email").html("Error!");
  15. }
  16. }, "json"
  17. );

  18. return false;// stop form from refreshing the page
  19. });
  20. }); // end document ready
Works properly, but...

  1. $(document).ready(function() {

  2. // register form onsubmit function
  3. $('#register_form').submit(function() {
  4. // declare variables
  5.                 var input_email; input_email = $("#register_form_input_email").val();

  6. // verify email
  7.   $.post("emailverifier.php", { email: input_email },
  8. function(data) {
  9. if (data.valid == 1) {
  10. // display ok
  11. $("#register_form_span_email").html("Ok!");
  12. } else {
  13. // display error
  14. $("#register_form_span_email").html("Error!");
  15. }
  16. }, "json"
  17. );

  18. if (1=1) {
  19. alert("One indeed equals one!");
  20. } else {
  21. alert("What the...?!?");
  22. }

  23. return false;// stop form from refreshing the page
  24. });
  25. }); // 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