Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Someone to look over code and help me find error (simple newbie problem)

    Hi.

    I'm working on learning about cookies. I've got a very short sample script given to me in class and I found the same script in a Javascript book (I guess I figured out what the teacher's been reading).

    When I open this script in IE, I get a Javascript error that 'userName is undefined' at line 23.

    Here's a link to the page where you can try it out... www.detailsfree.com/cscd378/cookie.html

    Here's the code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Cookie</title>
    <script language="Javascript" type="text/javascript">
      <!-- Hide script from older browers
      expireDate = new Date();
      expireDate.setMonth(expireDate.getMonth()+6);
    	
      userName = "";
      if (document.cookie != "" {
        userName = document.cookie.split("=")[1];
      } // end if
    	
      function setCookie() {
        userName = document.myForm.nameField.value;
        document.cookie = "userName=" + userName + "; expires=" + expireDate.toGMTString();
      } // end function
      //-->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" onload="document.myForm.nameField.value = userName">
      <form name="myForm" action="#">
        <h1>Enter your name: <input type="text" name="nameField" onblur="setCookie()" /></h1>
      </form>
    </body>
    </html>
    I'd appreciate any feedback on this. Thanks.

    David

  • #2
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Found the error.

    I had a missing right parenthesis ')'.

    Davd


  •  

    Posting Permissions

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