Im decent at html& javascript, but, i still need some help implementing some code cause i have no idea were to put the exact code, I have it set up so when you go to my website, you are prompted to type in a codename, and it saves it in your cookies, so next time you visit, it checks your cookies and greets you with your codename. I want to make it so when you visit, it changes the greeting based on what day it is. here is a snippit of my web code.
Code:
<html> <head> <script type="text/javascript"> // This is the Script for the popup Window function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } }
function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; }
function checkCookie() { var username=getCookie("username"); if (username!=null && username!="") { alert("Welcome back " + username); } else { username=prompt("Please enter your code name:",""); if (username!=null && username!="") { setCookie("username",username,365); } } } // This is the end </script> </head> <body onload="checkCookie()"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>ScratchMillitaryGames</title> </head>
Fri Aug 12, 2011 3:11 am
Dr. Evil
Joined: Mon Aug 17, 2009 3:00 am Posts: 242 Location: The Great White North
Re: I NEED HELP FROM JAVASCRIPT PEOPLE...
You mean like this?
Code:
<html> <head> <script type="text/javascript"> // This is the Script for the popup Window function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } }
function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; }
function checkCookie() { var username=getCookie("username"); if (username!=null && username!="") { var d=new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="FRIDAY FRIDAY GOTTA GET DOWN ON FRIDAY"; weekday[6]="Saturday";
alert("Welcome bacak " + username + ". Today is " + weekday[d.getDay()] + "."); } else { username=prompt("Please enter your code name:",""); if (username!=null && username!="") { setCookie("username",username,365); } } } // This is the end </script> </head> <body onload="checkCookie()"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>ScratchMillitaryGames</title> </head> <body> <h1><a href="http://www.w3schools.com/jS/js_obj_date.asp">herp derp. read this.</a></h1> <p>(you should google this kinda junk. documentation is your friend.)</p> </body> </html>
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum