JavaScript - Displaying Multiple, Identical Cookies?
Hello all!
Quick question regarding basic cookies. I have a button that runs a function that creates a cookie onclick; document.cookie = ("cookie1=500"); whenever i display this later, despite the fact i've clicked the button 3 times. It only displays once. Is there a way I could display this AS MANY TIMES as the button was clicked. Any help is appreciated. Code: <script type="text/javascript"> var cookies = document.cookie; var cookie_name = new Array(); var cookie_value = new Array(); if (cookies.length > 0 ) { var cookies = cookies.split("; "); for( var x = 0 ; x < cookies.length ; x++ ) { var cookie_parts = cookies[x].split("="); cookie_name[x] = cookie_parts[0]; cookie_value[x] = cookie_parts[1]; } } function writeProducts() { function removeItem() { cookie_name[x] + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; } var total = 0; var tempstring = ""; var prodTable = document.getElementById('tblProducts'); var prodRow; var prodQuantity; var prodName; var prodPrice; for( var x = 0 ; x < (cookie_name.length) ; x = x + 1) { prodRow = document.createElement('tr'); prodName = document.createElement('td'); prodPrice = document.createElement('td'); prodCheck = document.createElement('td'); prodName.innerHTML = cookie_name[x]; prodPrice.innerHTML = "$" + cookie_value[x]; prodCheck.innerHTML = tempstring + '<input type="button" value="Remove from Cart" />' total = parseInt(total + parseInt(cookie_value[x])); prodRow.appendChild(prodName); prodRow.appendChild(prodPrice); prodRow.appendChild(prodCheck); prodTable.appendChild(prodRow); } document.getElementById('spnProducts').innerHTML = tempstring; tempstring = tempstring + "Total :" + " " + '$' + total; document.getElementById('spnTotal').innerHTML = tempstring; } <script> Similar TutorialsHi! I'm trying to make a multiple choice quiz using javascript. I downloaded codes from http://www.javascriptkit.com/script/cut180.shtml But when I used it nothing comes up on the results (number of correct answer, number of wrong answer and percentage) as well as the solution box is empty. I tried it on Google Chrome and it says "Your browser does not accept cookies. Please adjust your settings." So I tried it in Safari because that's what we use in school and it doesn't work. The results and solution box is empty. I am guessing that problem is with cookies? Please help me. Here are my codes: - Quiz //Enter total number of questions: var totalquestions=10 //Enter the solutions corresponding to each question: var correctchoices=new Array() correctchoices[1]='a' //question 1 solution correctchoices[2]='d' //question 2 solution, and so on. correctchoices[3]='b' correctchoices[4]='b' correctchoices[5]='c' correctchoices[6]='b' correctchoices[7]='a' correctchoices[8]='c' correctchoices[9]='d' correctchoices[10]='b' /////Don't edit beyond here////////////////////////// function gradeit(){ var incorrect=null for (q=1;q<=totalquestions;q++){ var thequestion=eval("document.myquiz.question"+q) for (c=0;c<thequestion.length;c++){ if (thequestion[c].checked==true) actualchoices[q]=thequestion[c].value } if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice if (incorrect==null) incorrect=q else incorrect+="/"+q } } if (incorrect==null) incorrect="a/b" document.cookie='q='+incorrect if (document.cookie=='') alert("Your browser does not accept cookies. Please adjust your browser settings.") else window.location="results.htm" } function showsolution(){ var win2=window.open("","win2","width=200,height=350, scrollbars") win2.focus() win2.document.open() win2.document.write('<title>Solution</title>') win2.document.write('<body bgcolor="#FFFFFF">') win2.document.write('<center><h3>Solution to Quiz</h3></center>') win2.document.write('<center><font face="Arial">') for (i=1;i<=totalquestions;i++){ for (temp=0;temp<incorrect.length;temp++){ if (i==incorrect[temp]) wrong=1 } if (wrong==1){ win2.document.write("Question "+i+"="+correctchoices[i].fontcolor("red")+"<br>") wrong=0 } else win2.document.write("Question "+i+"="+correctchoices[i]+"<br>") } win2.document.write('</center></font>') win2.document.close() } ______________________________________________________________ For Results <html> <head> <title>Instant Quiz Results</title> </head> <body bgcolor="#FFFFFF"> <p align="center"><strong><font face="Arial"> <script src="quizconfig.js"> </script>Quiz Results Summary</font></strong></p> <div align="center"><center> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form method="POST" name="result"><table border="0" width="100%" cellpadding="0" height="116"> <tr> <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Number Of Correct Questions:</font></strong></td> <td height="25"><p><input type="text" name="p" size="24"></td> </tr> <tr> <td height="17" bgcolor="#D3FFA8"><strong><font face="Arial">Wrong Questions:</font></strong></td> <td height="17"><p><textarea name="T2" rows="3" cols="24" wrap="virtual"></textarea></td> </tr> <tr> <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Grade Percentage:</font></strong></td> <td height="25"><input type="text" name="q" size="8"></td> </tr> </table> </form> </td> </tr> </table> </center></div> <form method="POST"><div align="center"><center><p> <script> var wrong=0 for (e=0;e<=2;e++) document.result[e].value="" var results=document.cookie.split(";") for (n=0;n<=results.length-1;n++){ if (results[n].charAt(1)=='q') parse=n } var incorrect=results[parse].split("=") incorrect=incorrect[1].split("/") if (incorrect[incorrect.length-1]=='b') incorrect="" document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%" for (temp=0;temp<incorrect.length;temp++) document.result[1].value+=incorrect[temp]+", " </script> <input type="button" value="Retake Quiz" name="B1" onClick="history.go(-1)"> <input type="button" value="Show Solution" name="B2" onClick="showsolution()"></p> </center></div> </form> </body> </html> Please help me. I've been trying to find out what is wrong with my codes for a week. Thanks in advance! I would like to use the gallery whose code is provided on this page: http://www.meadmiracle.com/SlidingGallery.aspx I tried to display two galleries with the same settings and so I put: $(function() { $('div.gallery img').slidingGallery({ container: $('div.gallery') }); $('div.gallery2 img').slidingGallery({ container: $('div.gallery2') }); }); with the divs being "gallery2" but the coding only works when I put the code without "gallery2". Am I coding it wrong? Greetings! Let me start by first stating that I've never really coded Javascript before in my life. Having said that, I'm not an idiot and I can generally pick up on things relatively quickly . So, now to the point. I'm currently creating a site in which I've incorporated Protoswitcher (http://cssrevolt.com/upload/files/pr...her/index.html). From what I can tell, it's a relatively simple script. Now the catch is that I wanted to have more than one switcher on my site. And this is where I get stuck. What I did initially was to basically copy the JS file (protoswitcher.js) and rename it something else (userbar.js, for example). I then changed the various places in the script which were previously for "var ProtoSwitcher" to "var UserBar", etc. I managed to get it all to work fine. Both the boxes show up, and they both work as they should (clicking on them changes select bits of CSS). Now the problem I'm having is that the original protoswitcher uses cookies to remember a persons preferences. I cannot for the life of me figure out how to get the "new" protoswitcher (userbar.js) to work with cookies as well. Any help would be much appreciated, and I'm sure I can give you a few dollars for your time . Please let me know if I haven't made sense. TLDL: I want to be able to use several protoswitchers with working cookies. I don't know how. Hey, I have a location lookup tool that pulls data from a Google Fusion table. User's type their address in and it drops a pin and info window at the place / result that matches their location. It works great with one location, but now I need it to display multiple results / drop multiple pins if they match the criteria Here's the working code that drops one pin (sorry it's a lot): Code: google.load('visualization', '1', {'packages':['corechart', 'table', 'geomap']}); var FusionTableID = 'tableid'; var map = null; var geocoder = null; var infowindow = null; var marker = null; function initialize() { geocoder = new google.maps.Geocoder(); infowindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50) }); // create the map var myOptions = { zoom: 7, center: new google.maps.LatLng(41.9908, -93.4208), mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); layer = new google.maps.FusionTablesLayer({ query: {from:FusionTableID}, styles: [{ polygonOptions: { fillColor:'#000000', fillOpacity: 0.01, strokeColor:'#000000', strokeOpacity: 0.01 } }], suppressInfoWindows:true }); layer.setMap(map); google.maps.event.addListener(layer, "click", function(e) { var content = "<b>"+e.row['name'].value+"</b>"; infowindow.setContent(content); infowindow.setPosition(locationgeocode); infowindow.open(map); }); document.getElementById('submit').onclick = function() { document.getElementById("submit").value = "Searching"; }; } function showAddress(address) { var contentString = address+"<br>Outside Area"; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = results[0].geometry.location; contentString += "<br>"; // query FT for data var queryText ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01));"; // document.getElementById('FTQuery').innerHTML = queryText; queryText = encodeURIComponent(queryText); var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText); //set the callback function query.send(openInfoWindowOnMarker); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function openInfoWindowOnMarker(response) { if (!response) { alert('no response'); return; } if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } FTresponse = response; //for more information on the response object, see the documentation //http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse numRows = response.getDataTable().getNumberOfRows(); numCols = response.getDataTable().getNumberOfColumns(); var content = "<b>Outside of Iowa</b><!--"; var unionBounds = null; // alert(numRows); for (var i=0; i < numRows; i++) { var county = FTresponse.getDataTable().getValue(i,0); var precinct = FTresponse.getDataTable().getValue(i,1); var locationname = FTresponse.getDataTable().getValue(i,2); var locationaddress = FTresponse.getDataTable().getValue(i,3); var locationcity = FTresponse.getDataTable().getValue(i,4); var locationstate = FTresponse.getDataTable().getValue(i,5); var locationzip = FTresponse.getDataTable().getValue(i,6); var locationgeocode = FTresponse.getDataTable().getValue(i,7); // var kml = FTresponse.getDataTable().getValue(i,1); // create a geoXml3 parser for the click handlers content = "<b>"+locationname+"</b><br />"+locationaddress+"<br />"+locationcity+locationstate+" "+locationzip+"<br/><a href='http://maps.google.com/maps?daddr="+locationaddress+" "+locationcity+" IA "+locationzip+"' target='_blank' >Click here for Directions</a><br /></br></p><!--"; /* var geoXml = new geoXML3.parser({ map: map, zoom: false }); // alert(kml); geoXml.parseKmlString("<Placemark>"+kml+"<\/Placemark>"); geoXml.docs[0].gpolygons[0].setMap(null); if (!unionBounds) unionBounds = geoXml.docs[0].gpolygons[0].bounds; else unionBounds.union(geoXml.docs[0].gpolygons[0].bounds); */ } // zoom to the bounds // map.fitBounds(unionBounds); setTimeout(function() { google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); infowindow.setContent(content+marker.getPosition().toUrlValue(6)); google.maps.event.trigger(marker, 'click'); document.getElementById("submit").value = "Search"; }, 150); geocoder.geocode( { 'address': locationaddress+","+locationcity+locationstate+" "+locationzip}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = results[0].geometry.location; map.setCenter(point); map.setZoom(12); if (marker && marker.setMap) marker.setMap(null); marker = new google.maps.Marker({ map: map, position: point }); }; }); } I basically need it to drop multiple pins if multiple queries match var queryText ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'Hours', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01));"; Any thoughts, fixes, or even a point in the right direction would be incredibly helpful. I'm really stuck on this one and have been trying at it for a couple of days now. Even something like getting it to print a second query that I can mark in the table as a second location would be helpful. Something like a second pin that matches: Code: var queryText2 ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'Hours', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01)); AND locationname = 'Location 2'"; Thanks!! I would like to somehow get both of these identical slideshow scripts working at the same time. Any help would be much appreciated! Code: <!-- dress --> <div class= dress> <div style="position:absolute; background-color:transparent; border-color: #000000; border:0px solid ; top: 443px; left: 346px; width:397px; height:255px;"> <script language="JavaScript1.2"> var variableslide=new Array() //variableslide[x]=["", "", ""] variableslide[0]=['dress/1.png', '', ''] variableslide[1]=['dress/2.png', '', ''] variableslide[2]=['dress/3.png', '', ''] //configure the below 3 variables to set the dimension/background color of the slideshow var slidewidth='395px' //set to width of LARGEST image in your slideshow var slideheight='255px' //set to height of LARGEST iamge in your slideshow, plus any text description var slidebgcolor='transparent' //configure the below variable to determine the delay between image rotations (in miliseconds) var slidedelay=200 ////Do not edit pass this line//////////////// var ie=document.all var dom=document.getElementById for (i=0;i<variableslide.length;i++){ var cacheimage=new Image() cacheimage.src=variableslide[i][0] } var currentslide=0 function rotateimages(){ contentcontainer='<center>' if (variableslide[currentslide][1]!="") contentcontainer+='<a href="'+variableslide[currentslide][1]+'">' contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">' if (variableslide[currentslide][1]!="") contentcontainer+='</a>' contentcontainer+='</center>' if (variableslide[currentslide][2]!="") contentcontainer+=variableslide[currentslide][2] if (document.layers){ crossrotateobj.document.write(contentcontainer) crossrotateobj.document.close() } else if (ie||dom) crossrotateobj.innerHTML=contentcontainer if (currentslide==variableslide.length-1) currentslide=0 else currentslide++ setTimeout("rotateimages()",slidedelay) } if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>') function start_slider(){ crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub if (document.layers) document.slidensmain.visibility="show" rotateimages() } if (ie||dom) start_slider() else if (document.layers) window.onload=start_slider </script> </div> <!-- end dress --> <!-- hair --> <div class="hair"> <div style="position:absolute; background-color:transparent; border: 0px solid; border-color: #000000; left:436px; top:105px; width:227px; height:227px;"> <script language="JavaScript1.2"> var variableslide=new Array() //variableslide[x]=["", "", ""] variableslide[0]=['hair/1.png', '', ''] variableslide[1]=['hair/2.png', '', ''] variableslide[2]=['hair/3.png', '', ''] //configure the below 3 variables to set the dimension/background color of the slideshow var slidewidth='227px' //set to width of LARGEST image in your slideshow var slideheight='227px' //set to height of LARGEST iamge in your slideshow, plus any text description var slidebgcolor='transparent' //configure the below variable to determine the delay between image rotations (in miliseconds) var slidedelay=100 ////Do not edit pass this line//////////////// var ie=document.all var dom=document.getElementById for (i=0;i<variableslide.length;i++){ var cacheimage=new Image() cacheimage.src=variableslide[i][0] } var currentslide=0 function rotateimages(){ contentcontainer='<center>' if (variableslide[currentslide][1]!="") contentcontainer+='<a href="'+variableslide[currentslide][1]+'">' contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">' if (variableslide[currentslide][1]!="") contentcontainer+='</a>' contentcontainer+='</center>' if (variableslide[currentslide][2]!="") contentcontainer+=variableslide[currentslide][2] if (document.layers){ crossrotateobj.document.write(contentcontainer) crossrotateobj.document.close() } else if (ie||dom) crossrotateobj.innerHTML=contentcontainer if (currentslide==variableslide.length-1) currentslide=0 else currentslide++ setTimeout("rotateimages()",slidedelay) } if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>') function start_slider(){ crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub if (document.layers) document.slidensmain.visibility="show" rotateimages() } if (ie||dom) start_slider() else if (document.layers) window.onload=start_slider </script> </div> <!-- end hair --> I need to declare a variable (astString) and initialise it with a string of asterisks. astString needs to be the same length as another variable (otherString). otherString changes it value regularly so I think I need to use the .length property in some way but I can't see how! This should be simple but it's eluding me completely. Hi there, I've modified some code I found with a single variable & function to not allow certain keyboard input from a form (I eventually want this info to go into a cookie). I made two variables & functions; one which would not allow text, and one which would not allow numbers. The (new) text variable/function works fine, but the (modified) number variable/function only disallows the numbers 8 & 9. Please look at my code, try it (it doesn't work in IE8 or Firefox), and let me know how to fix it. Thanks, mitchellA PS: this is my first posting and I'm not sure I've followed the rules properly. Code: <html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Character Removal Test - by mitchellA</title> <script language="javascript" type="text/javascript"> /* Visit http://www.yaldex.com/ for full source code and get more free JavaScript, CSS and DHTML scripts! */ /* This script has been heavily modified from the original by mitchellA. */ <!-- Begin var only_t = /[$\\@\\\#\%\^\&\*\(\)\[\]\+\ \{\}\`\~\=\|\/\?\.\,\<\>\'\"\!\:\;\0\1\2\3\4\5\6\7\8\9]/; var only_n = /[$\\@\\\#\%\^\&\*\(\)\[\]\+\ \{\}\`\~\=\|\/\?\.\,\<\>\'\"\!\:\;\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z]/; function chk_t(val) { var strPass = val.value; var strLength = strPass.length; var lchar_1 = val.value.charAt((strLength) - 1); if(lchar_1.search(only_t) != -1) { var tst = val.value.substring(0, (strLength) - 1); val.value = tst; } } function chk_n(val) { var strPass = val.value; var strLength = strPass.length; var lchar_2 = val.value.charAt((strLength) - 1); if(lchar_2.search(only_n) != -1) { var tst = val.value.substring(0, (strLength) - 1); val.value = tst; } } function chk2(form) { if(form.value.length < 1) { alert("Missing something."); return false; } if((form.value.search(only_t) == -1) ||(form.value.search(only_n) == -1)) { alert("Seems to be working."); return false; } } // End --> </script> </head> <form name=get_info onSubmit="return chk2(this.f_name); return chk2(this.l_name); return chk2(this.exp_hrs);"> <br> <br> First Name: <input type="text" name="f_name" size="25" maxlength="15" value="" onKeyUp="javascript:chk_t(get_info.f_name);"> <br> <br> Last Name: <input type="text" name="l_name" size="25" maxlength="20" value="" onKeyUp="javascript:chk_t(get_info.l_name);"> <br> <br> How many minutes do you want your cookie to last (10 - 60): <input type="text" name="exp_mins" size="3" maxlength="2" value="" onKeyUp="javascript:chk_n(get_info.exp_mins);"> <br> <br> <input type=submit value=Continue> <br> </form> <body> </body> </html> Ahoy, Lemme try to explain this as best as I can. Bullet points might help: When someone clicks on an image here (http://gta.kwivia.co.uk/gta-iv/), the rest of the images collapse and become invisible Below the image, some links appear Also, there will be a "show other images" button which will then show the rest of the images http://gta.kwivia.co.uk/gta-iv/ I will appreciate all solutions to this problem. If you need to know anything, simply ask me. Ive looked it up on google and yahoo but i just cant find good explanations on how to use cookies?
Hi, Im a bit stuck on something, any help is greatly appreciated. I want a user to input a name, age, gender, city into a form, this gets stored in some cookies and when they click submit they are taken to another page where their details are displayed in the webpage. Thanks for the help. Hello, I know there are dozens of threads on this topic but I can't figure out how to do what I want to do. I have three variables I want to store in a cookie when a user leaves this page which is a college project: http://jimbolgs.agilityhoster.com/wo.../ClockUTC.html They are (from the linked JS file): extraMins, geoLoc, UTCHours. I would also like to retrieve them on return to the page. Any help appreciated, Thanks. If I create a cookie in PHP here. PHP Code: setcookie('cookie_cl_'.$client_id, 'cookie_cl_'.$client_id, $time, "/","", 0); the php script is set on domain B the javascript I want to read the cookie is set on domain B as well However, the hosted on DOMAIN A Code: <script src=domain B .js> I want the cookie to remain on domain B, but if I open the JS file using domain A, both php and JS are using domain B, though I can't seem to get the JS to find the cookie, is it looking at domain A ? am I suppose to set a domain on cookie for this to work? Hopefully this makes sense. Hi there, I am writing an extension for google chrome (or at least trying to, it's my first project), and I'm kinda stuck on one part. I'd like to save 2 variables, called "c" and "notes". I'd like it to get the cookies onLoad, and save them onUnload. I've tried different codes, but right now I just can't figure out how to set notes and c to the value of the cookie. Could anyone please help me? Thanks in advance. Hi all, I need some help. I have a javascript thing on my site that changes the css layout from standard to alternate, and that works fine. Now I am wondering if it's possible for it to store a cookie, that when any of the pages on my site (this javascript thing is on every page) are re-loaded or the user navigates to a different page, it will keep the alternate stylesheet. Then, when it is changed back, the cookie gets deleted. Here's my code: Header: Code: <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" title="default" /> <link rel="alternate stylesheet" href="/wp-content/themes/new/darkside.css" type="text/css" media="screen" title="darkside" /> <script language="javascript" src="/wp-content/themes/new/darkside.js"></script> Darkside.js Code: // *** TO BE CUSTOMISED *** var style_cookie_name = "style" ; var style_cookie_duration = 30 ; // *** END OF CUSTOMISABLE SECTION *** function switch_style ( css_title ) { // You may use this script on your site free of charge provided // you do not remote this notice or the URL below. Script from // http://www.thesitewizard.com/javascripts/change-style-sheets.shtml var i, link_tag ; for (i = 0, link_tag = document.getElementsByTagName("link") ; i < link_tag.length ; i++ ) { if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title) { link_tag[i].disabled = true ; if (link_tag[i].title == css_title) { link_tag[i].disabled = false ; } } set_cookie( style_cookie_name, css_title, style_cookie_duration ); } } function set_style_from_cookie() { var css_title = get_cookie( style_cookie_name ); if (css_title.length) { switch_style( css_title ); } } function set_cookie ( cookie_name, cookie_value, lifespan_in_days, valid_domain ) { // http://www.thesitewizard.com/javascripts/cookies.shtml var domain_string = valid_domain ? ("; domain=" + valid_domain) : '' ; document.cookie = cookie_name + "=" + encodeURIComponent( cookie_value ) + "; max-age=" + 60 * 60 * 24 * lifespan_in_days + "; path=/" + domain_string ; } function get_cookie ( cookie_name ) { // http://www.thesitewizard.com/javascripts/cookies.shtml var cookie_string = document.cookie ; if (cookie_string.length != 0) { var cookie_value = cookie_string.match ( '(^|;)[\s]*' + cookie_name + '=([^;]*)' ); return decodeURIComponent ( cookie_value[2] ) ; } return '' ; } EDIT: Actually, this is what happens: The user enters the konami code and a div shows/hides. There you are given the option to turn off/on the alternate style. Then I want the cookie to begin.. Please assist, I have the following code to remember form inormation but it does not seem to work. Probably something stupid. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Contact Page</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="yorkie.css" type="text/css" /> <script type="text/javascript"> /* <![CDATA[ */ // Confirm resetting of forms. function confirmReset() { var resetForm = confirm("Are you sure you want to reset the form?"); if (resetForm == true) return true; return false; } // If box clicked value within disappears function Focus(element) { if (element.value == element.defaultValue) { element.value = ''; } } // If nothing typed and box onblur the default value is restored within function Blank(element) { if (element.value == '') { element.value = element.defaultValue; } } // Submission of Contact Form Verified function verifySubmission() { var retValue = true; if (document.forms[2].email.value == "Enter Email Address" || document.forms[2].firstname.value == "Enter First Name" || document.forms[2].lastname.value == "Enter Last Name" || document.forms[2].telephone.value == "Enter Contact number") { window.alert("You did not fill in one of the following required fields: First Name, Last Name, Email Address, or Telephone Number."); retValue = false; } return retValue; } // Email address verified as a valid email address function validateEmail(formObject) { var email = formObject.value; var emailCheck = /^[_\w\-]+(\.[_\w\-]+)*@[\w\-]+(\.[\w\-]+)*(\.[\D]{2,3})$/; if (emailCheck.test(email) == false) { window.alert("The e-mail address you entered does not appear to be valid."); formObject.value = formObject.defaultValue; return false; } formObject.value = email.toLowerCase(); return true; } // Telephone number verified as a valid 10 digit number with no alpha characters function verifyPhone(number) { var phone = number.value; var phoneCheck = /^(\d{10})$/; if(phoneCheck.test(phone) == false) { window.alert("The telephone number you entered does not appear to be valid."); number.value = number.defaultValue; return false; } return true; } // Show additional contact form details onclick of yes radio button function showDiv() { document.getElementById('breeders').style.visibility = 'visible'; } // Hide certain contact form info onclick of No radio button function hideDiv() { document.getElementById('breeders').style.visibility = 'hidden'; } // SAVE FORM INFORMATION FOR THE NEXT VISIT function saveSelections(frm) { var setvalue; var fieldType; var index; var formname = frm.name; // CookieExpiry in 30 days. var today = new Date(); var exp = new Date(today.getTime()+30*24*60*60*1000); var string = "formname=" + formname + "|"; var cookieName = formname; var n = frm.length; for (i = 0; i < n; i++) { e = frm[i].name; fieldValue = frm[i].value; fieldType = frm[i].type; // Radio Buttons if (fieldType == "radio") { for (x=0; x < frm.elements[e].length; x++) { if (frm.elements[e][x].checked) { index = x } } string = string + index + "\|"; } // Text, Textarea, and dropdowns if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select")) { string = string + frm.elements[e].value + "\|"; } // Checkboxes if (fieldType == "checkbox") { if (frm.elements[e].checked==true) { var setvalue = "1"; } if (frm.elements[e].checked==false) { var setvalue = "0"; } string = string + setvalue + "\|"; } // Hidden field if (fieldType == "hidden") { string = string + frm.elements[e].value + "\|"; } } setCookie(cookieName, string, exp); } // Load Form Fields from saved cookie function loadSelections(frm) { var e; var z; var x; var cookieName; var fieldArray; var fieldValues; var fieldValue; var formname = frm.id; // Retrieve form elements from cookie and split into array. cookieName = formname; fieldValues = getCookie(cookieName); fieldArray = fieldValues.split("\|"); var n = frm.length; for (i = 0; i < n; i++) { e = frm[i].name; z = i; z++; var fieldType = frm[i].type; var fieldValue = fieldArray[z]; // Radio Buttons if (fieldType == "radio") { x = fieldValue; frm.elements[e][x].checked = true; } // Text, Textarea, and dropdowns if ((fieldType == "text") || (fieldType == "textarea") || (fieldType == "select")) { frm.elements[e].value = fieldValue; } // Checkboxes if (fieldType == "checkbox") { var fld_checkbox = fieldValue; if (fld_checkbox == "1") { frm.elements[e].checked = true; } } // Hidden fields if (fieldType == "hidden") { frm.elements[e].value = fieldValue; } } } // COOKIE FUNCTIONS function setCookie(name, value, expires) { document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : ""); } function getCookie(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else { begin += 2; } var end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; } return unescape(dc.substring(begin + prefix.length, end)); } /* ]]> */ </script> </head> <body class="contact" onload="var begin=setInterval('changeBanner()',9000); currentClock(); currentDate(); document.getElementById('breeders').style.visibility = 'hidden'; " onunload="saveSelections(document.forms[0])"> <table width="92%"> <form action="mailto:lynette@sayorkies.co.za, subject=Contact Form" method="post" enctype="text/plain" onsubmit="return verifySubmission()" onreset="return confirmReset();"> <table class="center" cellpadding="5" border="1"> <!-- This enters a horizontal line --> <tr><td><hr /></td></tr> <!-- This is for the personal information --> <tr><td><strong>Tell us who you a </strong></td></tr> <tr><td><input type="text" name="firstname" size="25" maxlength="35" value="Enter First Name" onfocus="Focus(this);" onblur="Blank(this);" /> * <input type="text" name="lastname" style="margin-left: 52px;" size="25" maxlength="35" value="Enter Last Name" onfocus="Focus(this);" onblur="Blank(this);" /> *</td></tr> <!-- This is for the contact information --> <tr><td><strong>Your Contact details:</strong></td></tr> <tr><td><input type="text" name="email" size="30" maxlength="60" value="Enter Email Address" onfocus="Focus(this);" onblur="Blank(this); validateEmail(this)" /> * <input type="text" name="telephone" style="margin-left: 20px;" size="20" maxlength="10" value="Enter Contact number" onfocus="Focus(this);" onblur="Blank(this); verifyPhone(this)" /> * </td></tr> <!-- This is where you enter your message also select what type of message--> <tr><td><strong>Your Message:</strong></td></tr> <tr><td align="left">What is your message about?<br /> <input type="radio" name="type" value="compliment" /> Compliment <input type="radio" name="type" value="complaint" /> Complaint <input type="radio" name="type" value="general" checked="checked" /> General <input type="radio" name="type" value="enquiry" /> Enquiry <input type="radio" name="type" value="feedback" /> Feedback</td></tr> <tr><td align="center"><textarea name="message" rows="6" cols="45" onfocus="Focus(this);" onblur="Blank(this)">Enter your message here...</textarea></td></tr> <!-- Additional information --> <tr><td align="left">Are you looking to purchase a Yorkie puppy?<br /> <input type="radio" name="purchase" value="yes" /> Yes <input type="radio" name="purchase" value="no" checked="checked" /> No</td></tr> <tr><td align="left">Do you own a Yorkie?<br /> <input type="radio" name="owner" value="yes" onclick="showDiv()" /> Yes <input type="radio" name="owner" value="no" checked="checked" onclick="hideDiv()" /> No<br /> <!-- If answer is no above the below questions are hidden, if yes then they appear --> <div id="breeders"> How many? <select name="qnty" size="1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5+</option></select> Are you a breeder? <input type="radio" name="breeder" value="yes" /> Yes <input type="radio" name="breeder" value="no" checked="checked" /> No</div></td></tr> <!-- Subscriptions --> <tr><td align="left">Do you wish to subscribe to the following?<br /> <input type="checkbox" name="subscribe" value="letter" checked="checked" /> Monthly Newsletter<br /> <input type="checkbox" name="subscribe" value="pups" /> Notification of a new litter<br /> <input type="checkbox" name="subscribe" value="updates" /> Notification of site updates<br /> <input type="checkbox" name="subscribe" value="register" /> Registrations</td></tr> <!-- Add a picture file --> <tr><td align="left">Upload your favourite Yorkie photo for the Picture of the Month.<br /> <input type="file" name="upload" accept="image/gif, image/jpeg" size="30" style="margin-left: 15px; margin-top:5px;" /></td></tr> <!-- This enters a horizontal line --> <tr><td><hr /></td></tr> <tr><td align="center">Required fields marked with *</td></tr> <!-- Buttons to clear the form or to submit the form --> <tr><td align="center"><input type="reset" value="Clear the Form" /> <input type="submit" value="Send your message" /></td></tr> </table></form<script type="text/javascript">loadSelections(document.forms[0]);</script> </body> </html> Console Error: Unable to get value of the property 'split': object is null or undefined for this line: Code: fieldArray = fieldValues.split("\|"); I am hitting a brick wall, dont know what to do? Dear friends I need an help i am facing problem with my referral link as they are not supporting cookies. when ever someone going to my link they will going to sign up page but if someone going to any other link provided on the website and returning on sign up page again my referral vanished I have creating an blog for in by embadding my referral link using iframe. can anybody help me to resolve this problem. thnx in advance. Hi there Guys, I'm looking to set a cookie that lasts 24 hours and has a specific name. The function is to check how many times a page has been visited by individual people and display it at the bottom of a HTML page. I have an existing script that holds the data for 6 months that i have found as below. My question, Can any one help me change this to the required time? I'm a Noob when it comes to java scripting but enthusiastic to learn. Code: <SCRIPT> expireDate = new Date expireDate.setMonth(expireDate.getMonth()+6) jcount = eval(cookieVal("jaafarCounter")) jcount++ document.cookie = "test jaafarCounter="+jcount+";expires=" + expireDate.toGMTString() function cookieVal(cookieName) { thisCookie = document.cookie.split("; ") for (i=0; i<thisCookie.length; i++){ if (cookieName == thisCookie[i].split("=")[0]){ return thisCookie[i].split("=")[1] } } return 0 } function page_counter(){ for (i=0;i<(3-jcount.toString().length);i++) document.write('<span class="counter">0</span>') for (y=0;y<(jcount.toString().length);y++) document.write('<span class="counter">'+jcount.toString().charAt(y)+'</span>') } </SCRIPT> Hi is it possible to email cookies to my email address. I have a order form and it saves all the information within a cookie and then goes to the payment page. I want to email the order details along with the payment detail to myself. Is this possible and how. Below example of my cookie: Code: function nextForm() { document.cookie = "prod1=" + encodeURIComponent(document.forms[0].prod1.value); document.cookie = "prod2=" + encodeURIComponent(document.forms[0].prod2.value); document.cookie = "prod3=" + encodeURIComponent(document.forms[0].prod3.value); location.href="Payment.html"; } I then have my payment cookie: Code: function paymentForm() { document.cookie = "FirstName=" + encodeURIComponent(document.forms[2].firstname.value) + ";secure=true"; document.cookie = "LastName=" + encodeURIComponent(document.forms[2].lastname.value) + ";secure=true"; document.cookie = "Email=" + encodeURIComponent(document.forms[2].email.value) + ";secure=true"; document.cookie = "PhoneNumber=" + encodeURIComponent(document.forms[2].telephone.value) + ";secure=true"; document.cookie = "Address=" + encodeURIComponent(document.forms[2].address1.value) + ";secure=true"; document.cookie = "Address=" + encodeURIComponent(document.forms[2].address2.value) + ";secure=true"; document.cookie = "City=" + encodeURIComponent(document.forms[2].city.value) + ";secure=true"; document.cookie = "Province=" + encodeURIComponent(document.forms[2].province.value) + ";secure=true"; document.cookie = "PostalCode=" + encodeURIComponent(document.forms[2].code.value) + ";secure=true"; document.cookie = "AmountDue=" + encodeURIComponent(document.forms[2].totalDue.value) + ";secure=true"; document.cookie = "CardName=" + encodeURIComponent(document.forms[2].cardName.value) + ";secure=true"; document.cookie = "CardNumber=" + encodeURIComponent(document.forms[2].cardNumber.value) + ";secure=true"; if (document.forms[2].correct.checked == true) document.cookie = "T&C Agreed = " + encodeURIComponent(true) + ";secure=true"; top.location.href="thankyou.html"; } and then my thankyou page from where it should be submitted to my email i am using a onload in the body but dont know what the code should look like.: Code: <body class="sale" onload="postCookie(); redirect(); return true"> <tr valign="middle"><td colspan="4" rowspan="10" align="center"><br /><hr /> <strong>Thank you for order! Your order will be processed within the next 48 hours.<br /> Your tracking number and postage details will be sent via email.<br /> You will now be taken back to the Home Page.<br /> Thanks for your support.</strong><br /><hr /><br /> <a href="http://www.sayorkies.co.za/home.html">Click here if your browser does not automatically redirect you.</a> </td></tr> Hi, I hope someone can help me. I'll be honest and say I don't know much about javascript, but am fairly comfortable in html. I am building a website that will have multiple image swaps on multiple pages. I am building this in wordpress, and I'm guessing that means my approach will be different than if I wasn't using wordpress. Here's how one page would work: There are 10 images shown. 1,2,3,4,5,6,7,8,9,10. When number 1 is clicked on, I want a new image - 1a. When 2 is clicked on, 2a. So there are 20 different images in all on a given page. Also, I want the user to be able to click on the image again to restore the original image. I would prefer onclick to onmouseover. There will be literally dozens of pages like this on the site, managed by wordpress, so hundreds of images to swap. Basically the first image is a question - the second image is the answer. Is this possible? hello to everyone i need a way to create a cookie based on user selection from a dropdown list and a radio button set . from the drop down list i control var city (1,2,3...) and from the radio buttons dow(f,s) , cdate(a,b,c,...) , ctime (a,b,c,...) it is a clock format and i want in the first page when the user select's the format that he wants it will remain in every page until he leaves the site Thankz |