Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JQuery function(data)

Status
Not open for further replies.

zura

Technical User
Sep 20, 2011
23
GE
This part [ append($error.clone().text('This email is already taken')) ] do not works...
???...

(This [ $(this).addClass('error') ] works correctly...)

thanks for help.

Code:
 $(document).ready(function() { 
	$('.btn-submit').click(function(e){	
		// Declare the function variables:
		// Parent form, form URL, email regex and the error HTML
		var $formId = $(this).parents('form');
		var formAction = $formId.attr('action');
		var $error = $('<span class="error"></span>');

		// Prepare the form for validation - remove previous errors
		$('li',$formId).removeClass('error');
		$('span.error').remove();

		// Validate all inputs with the class "required"
		$('.required',$formId).each(function(){
			var inputVal = $(this).val();
			var $parentTag = $(this).parent();
			if(inputVal == '){
				$parentTag.addClass('error').append($error.clone().text('Required Field'));		 		
			}
			if($(this).hasClass('email') == true){
			    $.post("[URL unfurl="true"]http://testingLoginEmail.php",{[/URL] user_name:$(this).val()} ,function(data){
                        if(data=='no'){
						    $('#mail').each(function(){ 						
			                $(this).addClass('error')[COLOR=red].append($error.clone().text('This email is already taken'))[/color]; 
                            });
                        }
                    });				
			}
		  });	

		// All validation complete - Check if any errors exist
		// If has errors
		if ($('span.error').length > 0) {			
			$('span.error').each(function(){
				
				// Set the distance for the error animation
				var distance = 5;
				
				// Get the error dimensions
				var width = $(this).outerWidth();
				
				// Calculate starting position
				var start = width + distance;
				
				// Set the initial CSS
				$(this).show().css({
					display: 'block',
					opacity: 0,
					right: -start+'px'
				})
				// Animate the error message
				.animate({
					right: -width+'px',
					opacity: 1
				}, 'slow');
				
			});
		} else {
			$formId.submit();
		}
		// Prevent form submission
			e.preventDefault();
	});	
	// Fade out error message when input field gains focus
	$('.required').focus(function(){
		var $parent = $(this).parent();
		$parent.removeClass('error');
		$('span.error',$parent).fadeOut();
	    });
});
Code:
<form id="form-sign-up" class="styled" action="reg.php" method="post">
	  	    <fieldset>
			  <dl>
			    <dt id="mail" ><label>EMAIL:</label>				 
				  <input name="mail" type="text" id="register-email" class="text-input required email" />
				</dt>
			  </dl>
			</fieldset>
</form>
 
What error do you get?

Have you tried contacting the website where you took the code?




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top