Results 1 to 2 of 2

Thread: form resets automatically

  1. #1
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default form resets automatically

    I have created a simple login form and am working on validation. Currently, I just check to make sure there is actually something filled out in the name field and, if not, when the user clicks the "submit" button, a div appears underneath the input indicating that the user needs to fill out their name.
    Code:
    $('form').submit(function(){
    	    		if ( $('#userName').val() == '') { $("<div class='error'>please provide your user name to continue</div>").insertAfter('#userName');}	
        		});
    when I submit the form, this works fine, but then the page quickly refreshes and it goes away. Does anyone know what's going on?

    You can see a sample at http://peter.byuipt.net/sites/rewardSystem/

  2. #2
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Resolved: return false

    OK, I figured it out. I forgot to return false, so that the form doesn't continue on to execute its "action" attribute. For clarification, here's the working code:
    Code:
        		$('form').submit(function(){
    	    		if ( $('#userName').val() == '') { $("<div class='error'>please provide your user name to continue</div>").insertAfter('#userName');
    	    		return false;}	
        		});

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •