Title: [jdjlist] RE: JavaScript and cookies
First of all you need to read my source. I am not using both at the same time.
 
First thing , I did the whole thing on the server. I could not get it to work.( No idea at this point, though I am moving back to trying again with the server way ) So I went the HTML way.
 
Believe me I was trying simple stuff, I am not a complete moron, not saying that you think I am, I just felt better saying that :)
 
As it turns out it was nothing to do with jsp pages, or my scripts, just retarded form element not working the way it really should, see my last post.
 
And thanks for you comments and assistance, I know your time is valuble
-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 14, 2003 12:57 PM
To: JDJList
Subject: [jdjlist] RE: _javascript_ and cookies

OK Dude, here is how to debug this kind of thing.  First of all you got to separate for yourself Tomcat cookies from _javascript_ cookies.  Both are stored in the client browser, one can read the other one...  but you will save yourself a lot of hassle if you do not mix the two.

If you can, I would do the whole cookie thing on the server. Period.  But if you have to do it in _javascript_, make a SEPARATE html page (no JSPs) and just try to set the cookie to say "Hello".  Look in the "Cookies" folder on windows to see if you have it there.  The easiest thing is to delete all cookies, restart browser and then you can find yours in there.  Use alert() liberally in your _javascript_ debugging -- you have little else for tools.

After you are able to alert() the cookie's "Hello" back out from your page, make the function more complex.  This is the easiest way to debug JS: start with small stuff all in one function, use alert() often -- don't write the whole complicated thing and then try to debug it.  There are literally millions of examples of JS cookies on the web:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=_javascript_+Cookies

and not all of them work right out of the box.

Good luck,

Greg


-----Original Message-----
From: Luc Foisy [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 14, 2003 7:16 AM
To: JDJList
Subject: [jdjlist] _javascript_ and cookies



Now that we established that _javascript_ != Java, i thought I'd come ask a _javascript_ question here, but really for lack of knowing any better place to go.

Running under tomcat with jsp pages, trying to create cookies, but they dont even seem to be made. I was wondering if anyone could point out something I am missing here.

Here is the jsp page in part

logon.jsp:
<HTML>
        <HEAD>
                <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
                <TITLE>ICRM</TITLE>
                <SCRIPT SRC=""></SCRIPT>
                <jsp:include page="style.inc" flush="true"/>
        </HEAD>
        <%
                if( request.getParameter("type").equals("role") )
                {
                        %>
                                <BODY BGCOLOR="#F0FFFF" >
                        <%
                }
                else
                {
                        %>
                                <BODY BGCOLOR="#F0FFFF" >
                        <%                     
                }
        %>
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" HEIGHT="100%">
                <TR>
                        <TD ALIGN="left" VALIGN="top" HEIGHT="139" WIDTH="142">
                                <IMG SRC="" HEIGHT="139" WIDTH="142">
                        </TD>
                        <TD ALIGN="left" VALIGN="top">
                                <IMG SRC=""><IMG SRC="" >
                        </TD>
                </TR>
                <TR>
                        <TD ALIGN="left" VALIGN="top" COLSPAN="2">

                <FORM NAME="logincheck" METHOD="post" ACTION=""type")%>">
                        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="640">
                                <TR>
                                        <TD WIDTH="20">
                                                Email:
                                        </TD>
                                        <TD>
                                                <INPUT TYPE="text" NAME="email" SIZE="30" MAXLENGTH="50">
                                        </TD>
                                </TR>
                                <TR>
                                        <TD WIDTH="20">
                                                Password:
                                        </TD>
                                        <TD>
                                                <INPUT TYPE="password" NAME="password" SIZE="30" MAXLENGTH="50"><BR>
                                        </TD>
                                </TR>
                                <%
                                        if( request.getParameter("type").equals("role") )
                                        {
                                                %>
                                                        <TR>
                                                                <TD WIDTH="20">
                                                                        Role:
                                                                </TD>
                                                                <TD>
                                                                        <%= TMHTTPLibrary.instance().recordSet2PickList(ICRMWebApp.getRoleRecordSet(),"roleid",false) %>

                                                                </TD>
                                                        </TR>
                                                <%
                                        }
                                %>
                                <TR>
                                        <TD WIDTH="20" ALIGN="right">
                                                <INPUT TYPE="checkbox" CHECKED NAME="rememberlogon">
                                        </TD>
                                        <TD>
                                                Remember Logon Information
                                        </TD>
                                </TR>
                                <TR>
                                        <TD COLSPAN="2">
                                                <%
                                                        if( request.getParameter("type").equals("role") )
                                                        {
                                                                %>
                                                                        <INPUT TYPE="image" ALT="Logon" VALUE="Logon" NAME="logon" SRC="" WIDTH="140" HEIGHT="27" ALIGN="top" BORDER="0" >

                                                                <%
                                                        }
                                                        else
                                                        {
                                                                %>
                                                                        <INPUT TYPE="image" ALT="Logon" VALUE="Logon" NAME="logon" SRC="" WIDTH="140" HEIGHT="27" ALIGN="top" BORDER="0" )>

                                                                <%                     
                                                        }
                                                %>
                                        </TD>
                                </TR>
                        </TABLE>
                </FORM>


Here is commonscript.js

function loadRoleLogonPage()
{
        document.logincheck.email.value=readEmbeddedCookie("icrmrolelogon","email");
        document.logincheck.password.value=readEmbeddedCookie("icrmrolelogon","password");
        document.logincheck.roleid.value=readEmbeddedCookie("icrmrolelogon","roleid");
}

function loadContactLogonPage()
{
        document.logincheck.email.value=readEmbeddedCookie("icrmcontactlogon","email");
        document.logincheck.password.value=readEmbeddedCookie("icrmcontactlogon","password");
}

function saveRoleLogon()
{
        if( document.logincheck.rememberlogon.checked )
        {
                writeEmbeddedCookie("icrmrolelogon","email",document.logincheck.email.value);
                writeEmbeddedCookie("icrmrolelogon","password",document.logincheck.password.value);
                writeEmbeddedCookie("icrmrolelogon","roleid",document.logincheck.roleid.value);
        }
}

function saveContactLogon()
{
        if( document.logincheck.rememberlogon.checked )
        {
                writeEmbeddedCookie("icrmcontactlogon","email",document.logincheck.email.value);
                writeEmbeddedCookie("icrmcontactlogon","password",document.logincheck.password.value);
        }
}

function readEmbeddedCookie(cookieName,itemToRead)
{
   var temp = getCookieValue(cookieName) + ";";
   var Pos = temp.indexOf("=",temp.indexOf(itemToRead + "="));
   if (temp.indexOf(itemToRead + "=") == -1) return "";
   return unescape(temp.substring(Pos + 1,temp.indexOf(";",Pos)));
}

function getCookieValue(name)
{
   var temp = document.cookie + ";";
   var Pos = temp.indexOf("=",temp.indexOf(name + "="));
   if (temp.indexOf(name + "=") == -1) return "";
   return unescape(temp.substring(Pos + 1,temp.indexOf(";",Pos)));
}

function writeEmbeddedCookie(cookieName,itemToWrite,valueToWrite)
{
   var temp = getCookieValue(cookieName) + ";";
   var Pos = temp.indexOf(itemToWrite + "=");
   if (Pos > 0)
   {
      var beginningOfBlock = temp.substring(0,Pos);
      var endOfBlock = temp.substring(temp.indexOf(";",Pos + itemToWrite.length) + 1,temp.length);
   }
   else if (Pos == 0)
   {
      beginningOfBlock = "";
      var endOfBlock = temp.substring(temp.indexOf(";",Pos + itemToWrite.length) + 1,temp.length);
   }
   else
   {
      beginningOfBlock = "";
      endOfBlock = temp;
   }
   temp = beginningOfBlock + itemToWrite + "=" + escape(valueToWrite) + ";" + endOfBlock;
   temp = temp.substring(0,temp.length - 1);
   writeCookie("172.16.0.222",2000,cookieName,temp );
}

function altSetCookie(name,value,expires,path)
{
   document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "");

}

function writeCookie(cookiePath,daysToExpire,name,contents)
{
   if (contents != getCookieValue(name))
   {
      if (contents != "")
      {
         var ExpireDate= new Date();
         ExpireDate.setTime(ExpireDate.getTime() + (daysToExpire * 24 * 3600 * 1000));
         altSetCookie(name,contents,ExpireDate,"172.16.0.222");
      }
   }
}


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to