JavaScript - Disappearing Cookies!
On my home page i have a form which accepts data and on clicking the accept 'button' executes a javascript routine that process' the data, sets a cookie, and sends the user to an appropriate page.
the set cookie data is as follows: Code: var expire=(new Date(2099, 1, 1)).toGMTString(); document.cookie = "cookie=privg; expires="+expire; window.location = "vip-skincare-online-shopping.html"; so far so good - i can hop about the pages on the website no problem but.... if i return to the home page that contains the original form, the cookie is deleted. This happens immediately i arrive at the page - i don't use the form. Can anyone suggest why this might be happening? I don't access the cookie anywhere else on that page, and the only other javascript on the page is google analytics stuff. Similar TutorialsHi, The following code is supposed to display and hide fields when clicking on radio buttons which is does correctly, it also gives the fields that are hidden a value so that it passes validation. T The problem is that when the user moves from one field to the next, it deletes the value that they have just entered. :S Any ideas why this might occur? Thanks! Code: <script language="javascript" type="text/javascript"> function showHideDivs(){ var category = ''; for(i=0; i < oRadBtns.length; i++){ if(oRadBtns[i].checked){ category = oRadBtns[i].value; } } switch (category){ case 'empresa': document.getElementById("empresa_nombre").value = ""; document.getElementById("contacto").value = ""; document.getElementById("nombre").style.display = "none"; document.getElementById("apellido").style.display = "none"; document.getElementById("company").style.display = "block"; document.getElementById("contact").style.display = "block"; document.getElementById("firstname").value = "nombre"; document.getElementById("lastname").value = "apellido"; break; case 'particular': document.getElementById("firstname").value = ""; document.getElementById("lastname").value = ""; document.getElementById("nombre").style.display = "block"; document.getElementById("apellido").style.display = "block"; document.getElementById("company").style.display = "none"; document.getElementById("contact").style.display = "none"; document.getElementById("empresa_nombre").value = "empresa"; document.getElementById("contacto").value = "contacto"; break; } } window.onload=function(){ oRadBtns = document.getElementById('dmsfrm').getElementsByTagName('input'); for(i=0; i < oRadBtns.length; i++){ oRadBtns[i].onclick = showHideDivs; } showHideDivs(); } </script> Code: <div class="radio_element"> <input type="radio" value="empresa" class="radio" id="empresa" name="categoria" <?php echo ($leadsEngine->getElementValue('categoria')!='particular')?'checked="checked"':'' ?> /> <span class="<?PHP if($leadsEngine->hasError('categoria')){echo 'error';} ?> ">Empresa</span> </div> <div class="radio_element"> <input type="radio" value="particular" class="radio" id="particular" name="categoria" <?php echo ($leadsEngine->getElementValue('categoria')=='particular')?'checked="checked"':'' ?> /> <span class="<?PHP if($leadsEngine->hasError('categoria')){echo 'error';} ?> ">Particular</span> </div> </div> How do I prevent my Link from disappearing?? When I click on the link, "Click Here" It display, "Look At Me!!" but the link, "Click Here" is GONE Is there a way to keep my link, "Click Here" from disappearing? So when I click on the link, "Click Here" the content, "Look At Me!!"should display as well. thanks Here are my codes Code: <html> <head> <script type="text/javascript"> function display() { document.writeln("Look At Me!!"); } </script> </head> <body> <a href="google.com" onClick="display()">Click Here</a> </body> </html> I have a form with multiple text entry fields. Some are input fields, and one is a textarea. I have the script (below) for a textarea in a form, to ensure that there is a max of 1500 characters. I am having two problems. 1) If there is an error on the form (for whatever reason), all of the text that was entered in the texarea, gets lost when the page reloads (this only happens for the textarea, the other input fields reprint the text). 2) When ever I try to press the "Tab" button on my keyboard, to tab out of the textarea to the next text box, it does not tab to the "next" text box, but instead it tabs "back" to the previous text box in the form. Here's what I have: Code: <head> <script type="text/javascript"> function ismaxlength(obj){ var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" if (obj.getAttribute && obj.value.length>mlength) obj.value=obj.value.substring(0,mlength) } </script> </head> <form> <tr> <td colspan="2"><textarea maxlength="1500" onkeyup="return ismaxlength(this)" name="blah_post" tabindex="1" style="display: block; width: 340px; height: 150px;" cols="60" rows="10" value="<?php print $blah_post;?>"></textarea></td> </tr> </form> Don't remember where I found the script but, I'm open to more simpler javascript suggestions as well.... I'm using two simple CSS rollovers for a prev/next arrow nav, combined with a JS script that lets the user manually tab/flip/swap through a few testimonials. You roll over the "next" button, it's highlighted, you click it, a new testimonial appears in place of the old one. Problem: the prev/next buttons are appearing and disappearing on click, seemingly randomly. I can't make any sense of it. Image: http://img3.imageshack.us/img3/8924/jsproblem.jpg I've tried adjusting the CSS container sizes, tried changing the positioning and even adding z-indexes in case the divs are accidentally overlapping. Gave items background colors to try to see the structure more clearly, for flaws. Nothing has worked. Any help much appreciated. I'm using this JS script for the tabs: Code: last_tab = 'tabTest1'; function show(layerName) { document.getElementById(layerName).style.display = '';} function hide(layerName) { document.getElementById(layerName).style.display = 'none';} function show_next(tab_name) { document.getElementById(last_tab).className = ''; var curr = document.getElementById(tab_name); curr.className=''; hide(last_tab+'_data'); show(tab_name+'_data'); last_tab=tab_name;} and this HTML: Code: <!-- start: testimonials --> <div id="tabTest1_data"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <p class="spotlightnav-content-title">Testimonials</p> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Excellent staff very courteous, friendly and professional, excellent stay, excellent meal.<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Janice, Georgia</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest6'); return false;" id="tabTest6" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" /></a> <a href="#" onClick="javascript:show_next('tabTest2'); return false;" id="tabTest2" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" /></a> </div> </div> </div> <div id="tabTest2_data" style="display: none;"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <a href="#" class="spotlightnav-content-title">Testimonials</a> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Absolutely marvelous. No problems.<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Christine, Taiwan</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest1'); return false;" id="tabTest1" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" style="height: 24px; width: 24px;" /></a> <a href="#" onClick="javascript:show_next('tabTest3'); return false;" id="tabTest3" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" style="height: 24px; width: 24px;" /></a> </div> </div> </div> <div id="tabTest3_data" style="display: none;"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <a href="#" class="spotlightnav-content-title">Testimonials</a> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Absolutely marvelous. No problems.<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Belle, Taiwan</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest2'); return false;" id="tabTest2" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" /></a> <a href="#" onClick="javascript:show_next('tabTest4'); return false;" id="tabTest4" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" /></a> </div> </div> </div> <div id="tabTest4_data" style="display: none;"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <a href="#" class="spotlightnav-content-title">Testimonials</a> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Vaguely not-terrible. Acceptable in a somewhat amazing way. ffffffffuuuuuuuuu<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Grace, Texas</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest3'); return false;" id="tabTest3" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" /></a> <a href="#" onClick="javascript:show_next('tabTest5'); return false;" id="tabTest5" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" /></a> </div> </div> </div> <div id="tabTest5_data" style="display: none;"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <a href="#" class="spotlightnav-content-title">Testimonials</a> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Damn fine place, yo.<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Slim, Bacon</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest4'); return false;" id="tabTest4" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" /></a> <a href="#" onClick="javascript:show_next('tabTest6'); return false;" id="tabTest6" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" /></a> </div> </div> </div> <div id="tabTest6_data" style="display: none;"> <div class="silo1"> <div class="spotlightnav-content-header-container"> <a href="#" class="spotlightnav-content-title">Testimonials</a> <a href="#" class="spotlightnav-content-more">View All</a> </div> <div class="content-container"> <p class="spotlightnav-testimonials"> <span class="color1">"</span>Blurry. But good.<span class="color1">"</span> </p> <p class="spotlightnav-testimonials-credit">Bob, California</p> </div> <div class="spolightnav-btns-container"> <a href="#" onClick="javascript:show_next('tabTest5'); return false;" id="tabTest5" class="spotlightnav-btn-left"><img src="images/clear.gif" width="24" height="24" /></a> <a href="#" onClick="javascript:show_next('tabTest1'); return false;" id="tabTest1" class="spotlightnav-btn-right"><img src="images/clear.gif" width="24" height="24" /></a> </div> </div> </div> I'm assuming this is primarily a JS problem, but if taking a look at the CSS is necessary, let me know and I'll post it. THANKS!!!!! I'm trying to understand how forms, data, php, javascript all work together. So 1) I hardcoded some html form fields with values using php using "echo", then 2) I dynamically created some more html form fields with values using javascript using "createElement" and appending to the html form element. When I click on the submit form, the php created form fields still show on the webpage, but the javascript dynamically created form fields disappear. Can anyone shed some light for me? Why are the javascript created form fields disappearing when I click on submit and not the PHP created form fields? Thank you! Code: <form method="post" id="commentform" action="<?php echo $PHP_SELF?>"> http://vietnamthereandback.com/mainpage.html The arrows next to the songs previews are randomly appearing/disappearing on page refresh. There are always 8 arrows, but each refresh shows the arrows in different places. This has really got me stumped. If anyone has any thoughts, I'd really appreciate hearing them. The basic button/arrow code is below. The only thing that changes in the MP3 file name. <code> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="30" height="30"> <PARAM NAME=movie VALUE="http://www.vietnamthereandback.com/Clips/audioplay.swf?file=http://www.vietnamthereandback.com/Clips/reflections.mp3&auto=no&sendstop=yes&repeat=1&buttondir=http://www.vietnamthereandback.com/Clips/buttons/negative_small&bgcolor=0xffffff&mode=playpause"> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE=transparent> <embed src="http://www.vietnamthereandback.com/Clips/audioplay.swf?file=http://www.vietnamthereandback.com/Clips/reflections.mp3&auto=no&sendstop=yes&repeat=1&buttondir=http://www.vietnamthereandback.com/Clips/buttons/negative_small&bgcolor=0xffffff&mode=playpause" quality=high wmode=transparent width="30" height="30" align="" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object> </code> 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> 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? Ive looked it up on google and yahoo but i just cant find good explanations on how to use cookies?
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. 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, 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. 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.. 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> 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. if I set a cookie for domain=.domain.com how do I read the cookie for domain=.domain.com, cause the javascript won't no that the cookie even exist? Been running a lot of test on this today, and can't find the right solution. Hi, the cookies I am trying to read are values from a form that were stored. The problem I am having is that one value form the form, the value is 5000, was stored as a cookie but I cannot read it. When I display it, it returns: [object HTMLInputElement]. The code for storing the value is this: Code: document.cookie = "bankRoll=" + encodeURIComponent(money) + "; expires=" + expireDate.toUTCString(); , where money = 5000. The code for reading the cookies is this: Code: var cookies = decodeURIComponent(document.cookie); var cookieNumber = new Array(10); cookieNumber = cookies.split("; "); for(var i = 0; i < cookieNumber.length; ++i) { var equalPos1 = cookieNumber[i].search("="); if (cookieNumber[i].substring(0, equalPos1) == "firstName") firstName = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "lastName") lastName = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "pCode") pCode = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "bankRoll") bankRoll = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "lastVisit") lastVisit = cookieNumber[i].substring(equalPos1 + 1); } The only one that does not display properly is the variable bankroll. All the others return the proper value. I would like to know how to fix my code so that the value 5000 is displayed. I'm displaying a page outside my server inside an iframe. I want to allow whatever is inside my iframe to set cookies. The website says, sorry your browser must allow cookies. My browser allows cookies, but because its in the iframe it doesn't allow them. I've read something about changing the header? What code would I put in my page.php to allow them? Thanks.
I've been stuck with this script for almost 2 weeks. I need to write a script that use cookies to keep in memory the user's preferences. First, a form to collect data. I need to know the name and second name of the user and his favorite color. After that, I need to valid all the values of the form, that is to say to be sure that they're not empty and that the color is a defined color. The form will be displayed at the first visit of the user then it will greet the user with a welcome message. Moreover, the background color will match the color that the user chose. The welcome message needs to be as follow: "Hi, Name secondName, Good morning! (if time is between 6am and 12), Good afternoon! (if time is between 12 and 6pm) or Good evening! (Between 6pm and 6am). Thank you sooooo much! |