Results 1 to 4 of 4

Thread: Javascript: Javascript problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Location
    Australia
    Posts
    12

    Javascript: Javascript problems

    I'm having a very big problem with a very small JavaScript
    Everytime I load the following page in IE6, it brings up the error:
    A runtime error has occured
    Do you wish to debug?

    Line: 7
    Error: 'return' statement outside of function
    Code:
    <html> 
       <head> 
          <title>Contact Us - CodingMasters</title> 
          <script language="javascript"> 
          <!--function checkform(){ 
             {if (document.formmail.body.value ="") or (document.formmail.changes.value ="") 
             alert("You did not fill in the comments box!") 
             return false} 
             else return true; 
          } 
          //--> 
          </script> 
       </head> 
       <body> 
          <P align="center"><FONT size="7" color="brown">CodingMasters</FONT></P> 
          <P align="center">"We give you what <EM>you</EM> want!"</P> 
          <BR> 
          <BR> 
          <center> 
             Here you can contact us using this form<BR> 
             <BR> 
             If <FONT color="#ff0000">*</FONT> is next to a field, it is compulsary<BR> 
             <form name="formmail" action="/cgi-bin/formmail/formmail.cgi" method="post" onsubmit="return checkForm()"> 
                <input type="hidden" name="recipient" value="[email protected]" style="WIDTH: 185px; HEIGHT: 22px" size="23"> 
                <p><b>Your Name:</b> <input name="realname" size="45"></p> 
                <br> 
                <p><b>Your Email Address:</b> <input name="email" size="45"></p> 
                <br> 
                <p><b>Comments or Suggestions:</b><br> 
                   <TEXTAREA name="body" rows="8" wrap="virtual" cols="60"></TEXTAREA><FONT color="#ff0000">*</FONT></p> 
                <br> 
                <p><b>What would you change about the site:</b><br> 
                   <TEXTAREA name="changes" rows="8" wrap="virtual" cols="60"></TEXTAREA><FONT color="#ff0000">*</FONT></p> 
                <br> 
                <p><b>Would you reccomend this site to your friends:</b><br> 
                   <input type="radio" name="friends" value="Yes" checked><input type="radio" name="friends" value="No"> 
                   <FONT color="#ff0000">*</FONT> 
                <p><input type="submit" value="Send Email"> <input type="reset" value="Reset Form"></p> 
             </form> 
             <br> 
             <br> 
             E-Mail us @ <A HREF="mailto:[email protected]">[email protected]</A><BR> 
             <BR> 
             <A HREF="maillist.htm">Back</A>:<A HREF="index.html">Home</A><br> 
             This site is hosted by <A HREF="http://www.aurorahost.net">AuroraHost</A> 
          </center> 
       </body> 
    </html>
    Thanks for any help anyone can give!

    Matthew G.

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Woah, your syntax is completely wrong in that function..

    Code:
    <script language="javascript"> 
          <!--function checkform() { 
             if (document.formmail.body.value ="") or (document.formmail.changes.value ="") 
             {
             alert("You did not fill in the comments box!") ;
             return false;
             } 
             else
             {
                 return true; 
             }
          } 
          //--> 
          </script>

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    To add, put the function keyword on its own line, not directly after the html comment. And the comparison operator is ==, not =.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    and it's
    if ((document.formmail.body.value =="") || (document.formmail.changes.value =="") )

    not

    if (document.formmail.body.value ="") or (document.formmail.changes.value ="")


    || is or, && is and
    Have I helped you? Please Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width