Mon, 2004-02-16 10:08
I am trying to Validate a form, when someone doesnt enter any information then it should bring up an alert.
I have only tryed it will one text feild
<HTML> <HEAD> <TITLE>Insert Title Here</TITLE> <META NAME="Author" CONTENT="Enter Name"> <META NAME="KeyWords" CONTENT="Enter all Keywords, no repeat of same word"> <META NAME="Description" CONTENT="Insert Website Discription"> <LINK REL="Stylesheet" TYPE="text/css" HREF="style.css"> <SCRIPT LANGUAGE="JavaScript"> <!-- function validate() { if (formObj.name.value="") { alert("Please Fil in Feild") }} //--> </SCRIPT> </HEAD> <BODY> <FORM onSubmit="validate()"> <TABLE WIDTH="30%" BORDER="0"> <TR> <TD> Name: </TD> <TD> <INPUT TYPE="text" CLASS="contact" SIZE="20" ID="name" NAME="name"><BR> </TD> <TR> <TD> Email Address: </TD> <TD> <INPUT TYPE="text" CLASS="contact"><BR> </TD> </TR> <TR> <TD> Comments: </TD> <TD> <INPUT TYPE="text" CLASS="contact"><BR> </TD> </TR> <TR> <TD> <INPUT TYPE="submit" value="Send" CLASS="contact"> <INPUT TYPE="reset" CLASS="contact"> </TR> </TABLE> </FORM> </BODY> </HTML>
Thank You
Rees
Mon, 2004-02-16 10:25
#1
Validate Form
Hi rmcivo1,
When assigning a value you use "="
When checking if values are equal you use "==".
Also the formObj has no value or isn't anything?
you need to get a handel on the form, try if(document.forms[0].name == "")
There are some good tutorials on the web just search for "javascript form validation"
Hope that helps
Mon, 2004-02-16 10:33
#2
Validate Form
Thank you Tony.
I didnt know that there was a deifference between the "=" and the "==", shows how much I know
Thank you Once Again
Rees