pleek Posted February 24, 2008 Share Posted February 24, 2008 ok so i have this code <html> <head> <body> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> if (document.cookie = "Show") { document.write("<b>SHOW</b>"); } else { document.write("<b>HIDE</b>"); } //SHOUT BOX MINUS & EXPAND function hide() { document.getElementById("frame1").height="0"; document.getElementById("BAR").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_4.gif"; document.getElementById("BAR").onclick=show; document.getElementById("BARUP").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_6.gif"; document.cookie = "Hidden"; } function show() { document.getElementById("frame1").height="250"; document.getElementById("BAR").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_3.gif"; document.getElementById("BAR").onclick=hide; document.getElementById("BARUP").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_5.gif"; document.cookie = "Show"; } //END SHOUT BOX MINUS & EXPAND </script> <IMG ID="BARUP" SRC="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_5.gif" WIDTH="100%" HEIGHT="6"> <!-- SHOUT BOX --> <IFRAME ID="frame1" SRC="http://www2.shoutmix.com/?pleek" WIDTH="100%" HEIGHT="275" FRAMEBORDER="0" ALIGN="Center" SCROLLING="no"> </IFRAME> <!-- END SHOUT BOX--> <IMG ID="BAR" CLASS="pointer" SRC="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_3.gif" WIDTH="100%" HEIGHT="15" ONCLICK="hide()"> <P>Use the following buttons to experiment with these statements:</P> <FORM> <INPUT TYPE="button" VALUE="display cookie" onClick="alert(document.cookie);"> </FORM> </head> </body> </html> Its supposed to change the words at the top from SHOW to HIDDEN acourding to the cookie. Now i change the cookie by colapsing the shoutbox. I then click show cookie and it says its HIDDEN. But when i click refresh it changes it right back to SHOW and the text at the top doesn't change. CAN anyone figure out what im doing wrong??????????????????? Quote Link to comment Share on other sites More sharing options...
phpQv11.0_IsKickButt Posted February 24, 2008 Share Posted February 24, 2008 Your not creating the cookie accurately. You leaving off the: domain, path, and expiration date/time. Do a Google search for "JavaScript Cookies"; you should be able to see examples of how to create a cookie. - Good Luck Quote Link to comment Share on other sites More sharing options...
pleek Posted February 24, 2008 Author Share Posted February 24, 2008 i have and i don't get it. document.cookie="nameofCookie=cookieData" from other things ive seen i can just use this, but i don't understand on how to use the if statement to check if the name is hidden or show. Can some one explain how to use the cookie to see if the text should be hidden or not? Quote Link to comment Share on other sites More sharing options...
pleek Posted February 24, 2008 Author Share Posted February 24, 2008 like say i have this code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Untitled</TITLE> <META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004"> </HEAD> <BODY> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> if (document.cookie = "shoutbox=hidden") { document.write("<B>WOW it works finally</B>"); } else { document.write("<B>YEAH!!!!</B>"); } document.cookie = "shoutbox=show; expires=15/02/2010 00:00:00"; </SCRIPT> <INPUT type="button" value="Get Cookie String" name="shoutbox" onClick='alert(document.cookie)'> </BODY> </HTML> What am i doing wrong, ive read all the stuff for like the first 3 sites that came up for "javascript cookies" and none of them help me with this part Quote Link to comment Share on other sites More sharing options...
pleek Posted February 24, 2008 Author Share Posted February 24, 2008 got a good place to learn? ive been reading all over the internet. I get how to set the cookie but not the syntack of it. And im really lost when useing it Quote Link to comment Share on other sites More sharing options...
phpQVersion25.0 Posted February 25, 2008 Share Posted February 25, 2008 Best bet - go buy you a book for beginners in javascript; probably would really help you with this. I don't have a good example for you off hand - Google Is Your Friend - LOL. - Good Luck Quote Link to comment Share on other sites More sharing options...
pleek Posted February 26, 2008 Author Share Posted February 26, 2008 ok I think i got the cookie part FINALLY!!!! Here is my new code, The cookie works in changing the text at the top to tell me which cookie is set but i can't figure out how to get it to run the show() hide() functions depending on the cookie. I tried just copy and pasting in the dom of the functions into my if/else command but that didn't work, can somebody help me out and tell me how to make it so if the cookie says hidden it will run the hide() function? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Untitled</TITLE> <META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004"> </HEAD> <BODY> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> if (document.cookie == "shoutbox=show") { document.write("<p>This is the show cookie</p>"); } else { document.write("<p>This is the hidden cookie</p>"); } function set_cookie() { document.cookie = "shoutbox=hidden; expires=13/06/2010 00:00:00"; } function remove_cookie() { document.cookie = "shoutbox=show; expires=13/06/2010 00:00:00"; } </SCRIPT> <INPUT TYPE="button" NAME="Get_Cookie" VALUE="Get Cookie" onClick="alert(document.cookie)"> <INPUT TYPE="button" NAME="Set_Cookie" VALUE="Set Cookie" onClick="set_cookie()"> <INPUT TYPE="button" NAME="Remove_Cookie" VALUE="Remove Cookie" onClick="remove_cookie()"> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> //SHOUT BOX MINUS & EXPAND function hide() { document.getElementById("frame1").height="0"; document.getElementById("BAR").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_4.gif"; document.getElementById("BAR").onclick=show; document.getElementById("BARUP").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_6.gif"; } function show() { document.getElementById("frame1").height="250"; document.getElementById("BAR").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_3.gif"; document.getElementById("BAR").onclick=hide; document.getElementById("BARUP").src="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_5.gif"; } //END SHOUT BOX MINUS & EXPAND </script> <IMG ID="BARUP" SRC="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_5.gif" WIDTH="100%" HEIGHT="6"> <!-- SHOUT BOX --> <IFRAME ID="frame1" SRC="http://www2.shoutmix.com/?pleek" WIDTH="100%" HEIGHT="275" FRAMEBORDER="0" ALIGN="Center" SCROLLING="no"> </IFRAME> <!-- END SHOUT BOX--> <IMG ID="BAR" CLASS="pointer" SRC="http://craigh.tlcrepair.net/mkportal/modules/gallery/album/a_3.gif" WIDTH="100%" HEIGHT="15" ONCLICK="hide()"> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted February 26, 2008 Share Posted February 26, 2008 http://www.quirksmode.org/js/cookies.html quirksmode is the best place to get cross browser compatable javascript code/explanations. Quote Link to comment Share on other sites More sharing options...
pleek Posted February 27, 2008 Author Share Posted February 27, 2008 does anybody here actually help people? or just say go search it? ive read all the information that showed up on google and the page the post above me said to read. Here is my code WHY WON'T IT WORK?????!?!?!?!?!? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Untitled</TITLE> <META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004"> </HEAD> <BODY> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> function hello() { document.write("<p>Here is some simple text</p>") } if (document.cookie == "shoutbox=show") { hello() document.write("<p>This is the show cookie</p>"); } if (document.cookie == "shoutbox=hidden") { document.write("<p>This is the hidden cookie</p>"); document.getElementById("frame1").height="0"; } function hide() { document.getElementById("frame1").height="0"; } function set_cookie() { document.cookie = "shoutbox=hidden; expires=13/06/2010 00:00:00"; } function remove_cookie() { document.cookie = "shoutbox=show; expires=13/06/2010 00:00:00"; } </SCRIPT> <INPUT TYPE="button" NAME="Get_Cookie" VALUE="Get Cookie" onClick="alert(document.cookie)"> <INPUT TYPE="button" NAME="Set_Cookie" VALUE="Set Cookie" onClick="set_cookie()"> <INPUT TYPE="button" NAME="Remove_Cookie" VALUE="Remove Cookie" onClick="remove_cookie()"> <INPUT TYPE="button" Name="Text" VALUE="Text" onClick="text()"> <INPUT TYPE="button" Name="hide" VALUE="hide" onClick="hide()"> <!-- SHOUT BOX --> <IFRAME ID="frame1" SRC="http://www2.shoutmix.com/?pleek" WIDTH="100%" HEIGHT="275" FRAMEBORDER="0" ALIGN="Center" SCROLLING="no"> </IFRAME> <!-- END SHOUT BOX--> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
fenway Posted February 27, 2008 Share Posted February 27, 2008 I don't see you using these functions: function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } Quote Link to comment Share on other sites More sharing options...
pleek Posted February 28, 2008 Author Share Posted February 28, 2008 so i Have to use those functions? what is wrong with the ones i wrote, they follow the guide that was posted for me to use. And if i use those functions then how do i use a if statement to run the hide() function if the cookie says hidden? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 28, 2008 Share Posted February 28, 2008 so i Have to use those functions? what is wrong with the ones i wrote, they follow the guide that was posted for me to use. And if i use those functions then how do i use a if statement to run the hide() function if the cookie says hidden? You don't have to use them... but they are known to work, and yours aren't. So I'd start with working code, get your script working, then rewrite them. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted February 28, 2008 Share Posted February 28, 2008 the quirksmode.org page I posted above says that the date part of the cookie should be in UTC (Greenwich) time in the format created by the Date.toGMTString() method. It should come out looking like the below which is definitely not what you have: document.cookie = 'ppkcookie2=yet another test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/'; If quirksmode says the date should be in the format above, I would take that seriously. Who knows javascript, quirksmode knows javascript. Just go ahead and use the functions posted on quirksmode and by fenway to set and test your cookies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.