2 replies [Last post]
rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 4 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

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

The Cyber World

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 1 day ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

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

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 4 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Validate Form

Thank you Tony.

I didnt know that there was a deifference between the "=" and the "==", shows how much I know Smile

Thank you Once Again
Rees

The Cyber World