Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: Form Validation


Message #1 by "Robert Nyman" <robert.nyman@c...> on Mon, 23 Dec 2002 14:39:22 +0100
It's because you don't have an end '}' to your else.

It should be like this:

else{
	alert("All ok");
	return true;
}


Full correct code below:


function contactCheck()
=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0if (document.contactform.first_name.value =3D=3D 
"")
=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0alert("First Name | Problem:\n\nYou forgot to 
enter\nyour first
name\n\nPlease enter it\n\nThis entry is required!.");
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.first_name.focus();
=A0=A0=A0=A0=A0=A0=A0=A0return false;
=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0if (document.contactform.last_name.value =3D=3D 
"")
=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0alert("Last Name | Problem:\n\nYou forgot to 
enter\nyour last
name\n\nPlease enter it\n\nThis entry is required!.");
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.last_name.focus();
=A0=A0=A0=A0=A0=A0=A0=A0return false;
=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0if 
(document.contactform.submit_by.value.indexOf("@") =3D=3D -1 ||
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.submit_by.value =3D=3D "")
=A0=A0=A0=A0=A0=A0=A0=A0{
	=A0=A0=A0=A0=A0=A0=A0=A0alert("Email Address | Problem:\n\nYou forgot 
to
enter\nyour
		email\n\nPlease enter it\n\nThis entry is required!.");
	=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.submit_by.focus();
	=A0=A0=A0=A0=A0=A0=A0=A0return false;
	}
=A0=A0=A0=A0=A0=A0=A0=A0else{
	=A0=A0=A0=A0=A0=A0=A0=A0alert("All ok");
	=A0=A0=A0=A0=A0=A0=A0=A0return true;=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0}
}


/Robert


-----Ursprungligt meddelande-----
Fr=E5n: Daryl Isaacs [mailto:idaryl@d...]
Skickat: den 23 december 2002 02:07
Till: JavaScript HowTo
=C4mne: [javascript_howto] Form Validation


I have a problem with a javascript form validation script I'm currently
using. The script below is what I normally use - however I added "=A0}
=A0=A0=A0=A0=A0=A0=A0=A0else{
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0alert("All ok");
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return true; " [I commented it out]
so it would notify the user that they had filled in the form correctly
prior
to submission. If I leave it out it works fine, but the client wants it
to tell
them the form is OK. What am I doing wrong here? Any ideas?


---------------------------

function contactCheck()
=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0if (document.contactform.first_name.value =3D=3D 
"")
=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0alert("First Name | Problem:\n\nYou forgot to 
enter\nyour first
name\n\nPlease enter it\n\nThis entry is required!.");
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.first_name.focus();
=A0=A0=A0=A0=A0=A0=A0=A0return false;
=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0if (document.contactform.last_name.value =3D=3D 
"")
=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0alert("Last Name | Problem:\n\nYou forgot to 
enter\nyour last
name\n\nPlease enter it\n\nThis entry is required!.");
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.last_name.focus();
=A0=A0=A0=A0=A0=A0=A0=A0return false;
=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0if 
(document.contactform.submit_by.value.indexOf("@") =3D=3D -1 ||
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.submit_by.value =3D=3D "")
=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0alert("Email Address | Problem:\n\nYou forgot to 
enter\nyour
email\n\nPlease enter it\n\nThis entry is required!.");
=A0=A0=A0=A0=A0=A0=A0=A0document.contactform.submit_by.focus();
=A0=A0=A0=A0=A0=A0=A0=A0return false;
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0//=A0}
=A0=A0=A0=A0=A0=A0=A0=A0// else{
=A0=A0=A0=A0=A0=A0=A0=A0=A0//=A0alert("All ok");
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0// return true;
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0}



  Return to Index