By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

New javascripter with a function/cookie problem!

P: 1
Here is the function

Expand|Select|Wrap|Line Numbers
  1. function setCookie()
  2. {
  3. cookieName = "dataCookie";
  4. var YouEntered
  5.  
  6. if(document.cookie != document.cookie)
  7. {index = document.cookie.indexOf(cookieName);}
  8. else
  9. {index = -1;}
  10.  
  11. if (index == -1)
  12. {
  13. YouEntered=document.getElementById("userName").value;
  14. document.cookie=cookie_name+"="+YouEntered+"; expires=Monday,04-Apr-2020 05:00:00 GMT";
  15. }
  16. }
  17.  
Here is the code in the default.htm
[HTML]<p>
<INPUT type="button" NAME="memberLoginButton" VALUE="Member Login" Id="submitButton"
onclick="return validate(); setCookie()">
</p[/HTML]
Nov 14 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
The problem here is the "return validate()" which won't allow the setCookie() function to execute. To solve the problem, put the setCookie function call within validate() or call it with an if condition, i.e. if (validate()) setCookie().
May 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.