Jump to content

if statement


jimfog

Recommended Posts

I am not so experienced in js and as such I have this question;Here is some code:

$(function() {    $('.error').hide();    $(".button").click(function() {		 $('.error').hide(); 	 	    var name = $("input#name").val(); 	    if (name == "") { 	  $("label#name_error").show(); 	  $("input#name").focus(); 	  return false;     }            	  // validate and process form here    });  });

Why the if statement above has a "return false" statement in it.Is there a difference in the false statement between PHP and JS.

Link to comment
Share on other sites

Return false returns the boolean "false" when the function is executed. Since this is a click event, that means that the default actions that clicking causes shouldn't occur. It's the same as in PHP.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...