Jump to content

What Have I Done Wrong?


Jamesking56
 Share

Recommended Posts

What is wrong with my Javascript Code?It was running then I added the Email Checks (Checks @ and where the dot is) but now I added that it won't run...It runs when a Form is submittedhere is my code:

<script type="text/javascript">function check(){	// Assign Positions	with(email)	{	apos_one = value.indexOf("@");	dotpos_one = value.lastIndexOf(".");	}		with(verify_email)	{	apos_two = value.indexOf("@");	dotpos_two = value.lastIndexOf(".");	}		// Check for Non-Blanks	if(document.registerform.username.value=="" || document.registerform.username.length==0)	{		alert('Please Fill in your Desired Username!');		document.registerform.username.focus();		return false;	}	else if(document.registerform.password.value=="" || document.registerform.password.length==0)	{		alert('Please Fill in your Desired Password!');		document.registerform.password.focus();		return false;	}	else if(document.registerform.verify_password.value=="" || document.registerform.verify_password.length==0)	{		alert('Please Verify your Password!');		document.registerform.verify_password.focus();		return false;	}	else if(document.registerform.email.value=="" || document.registerform.email.length==0)	{		alert('Please Fill in your Email Address!');		document.registerform.email.focus();		return false;	}	else if(document.registerform.verify_email.value=="" || document.registerform.verify_email.length==0)	{		alert('Please Verify your Email Address!');		document.registerform.verify_email.focus();		return false;	}		// Check Normal and Verify Fields Match	// Passwords	else if(document.registerform.password.value!==document.registerform.verify_password.value)	{		alert('Passwords Don\'t Match!');		document.registerform.password.focus();		return false;	}	// Emails	else if(document.registerform.email.value!==document.registerform.verify_email.value)	{		alert('Email Addresses Don\'t Match!');		document.registerform.email.focus();		return false;	}	// Check if Email Fields Contain an '@' Sign	// Check using IF Functions	else if(apos_one < 1 || dotpos_one-apos_one < 2) 	{		// WRONG		alert('Email Address not Real!' + '\n' + 'Please Use a Real Email!');		document.registerform.email.focus();		return false;	}	else if(apos_two<1||dotpos_one-apos_two<2) 	{		// WRONG		alert('Email Address not Real!' + '\n' + 'Please Use a Real Email!');		document.registerform.verify_email.focus();		return false;	}		// Finish JS Validation	else	{		return true;	}	}</script>	

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
 Share

×
×
  • Create New...