Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2005, 09:02 PM   PM User | #1
davenet
New to the CF scene

 
Join Date: Oct 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
davenet is an unknown quantity at this point
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
davenet is offline   Reply With Quote
Old 10-19-2005, 10:57 PM   PM User | #2
davenet
New to the CF scene

 
Join Date: Oct 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
davenet is an unknown quantity at this point
Found the error.

I had a missing right parenthesis ')'.

Davd
davenet is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:59 AM.


Advertisement
Log in to turn off these ads.