New javascripter with a function/cookie problem!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amesteri
    New Member
    • Nov 2006
    • 1

    New javascripter with a function/cookie problem!

    Here is the function

    [CODE=javascript]function setCookie()
    {
    cookieName = "dataCookie ";
    var YouEntered

    if(document.coo kie != document.cookie )
    {index = document.cookie .indexOf(cookie Name);}
    else
    {index = -1;}

    if (index == -1)
    {
    YouEntered=docu ment.getElement ById("userName" ).value;
    document.cookie =cookie_name+"= "+YouEntere d+"; expires=Monday, 04-Apr-2020 05:00:00 GMT";
    }
    }
    [/CODE]Here is the code in the default.htm
    [HTML]<p>
    <INPUT type="button" NAME="memberLog inButton" VALUE="Member Login" Id="submitButto n"
    onclick="return validate(); setCookie()">
    </p[/HTML]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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().

    Comment

    Working...