JavaScript - One Time Popup Using Cookies
Hi -
I have used two scripts that I found on the web - both proport to only load a popup once per session - one is from pc magazine April issue, another I will list here - they use cookies, here is my dir structure on my web site root dir1 dir2 dir3 .js is in root, pages in dir1 and dir2 and dir3 call it, popup comes up once per dir hit, not once per site hit! My site informationhighwaytohell.com go to travelogue, then move around, you see popup is loading more than once - what gives? The js is in a .js file that gets called by every page http://javascriptkit.com/popwin/index.shtml <script> //Popup Window Script //By JavaScript Kit (http://javascriptkit.com) //JavaScript tutorials and over 400+ free scripts function openpopup(){ var popurl="http://fullwebaddresshere" winpops=window.open(popurl,"","width=400,height=338,") } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { // if cookie exists offset += search.length // set index of beginning of value end = document.cookie.indexOf(";", offset); // set index of end of cookie value if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)) } } return returnvalue; } function loadornot(){ if (get_cookie('poppedup')==''){ openpopup() document.cookie="poppedup=yes" } } loadornot() </script> Similar TutorialsI'm trying to create a popup sign up form that will only popup every week. I don't want it to popup every time someone visits the site. I'm new to Javascript as a whole and can't seem to figure out how to set a cookie for a week and if there is no cookie (or the cookie has expired) it will popup automatically. If anyone can point out what I'm doing wrong it would be greatly appreciated. I feel like I'm so close and that the solution is staring me in the face. Here's the code that I have so far: 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() + 5); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkCookie() { var username=getCookie(exdate); if (exdate!=null && exdate!="") { //Do Nothing } else { $(document).ready(function() { var id = '#dialog'; //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(1000); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/100-$(id).height()/2); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(1000); $(id).animate({top:"+=300px"},1000); //if close button is clicked $('.window .close').click(function (e) { //Cancel the link behavior e.preventDefault(); $('.window').animate({right:"+=150px"}).animate({left:"1500px"}).fadeOut(50); $('#mask').hide(); }); //if NO Thanks button is clicked $('.window .noThanks').click(function (e) { //Cancel the link behavior e.preventDefault(); $('.window').animate({right:"+=150px"}).animate({left:"1500px"}).fadeOut(50); $('#mask').hide(); }); //if mask is clicked $('#mask').click(function () { $(this).hide(); $('.window').hide(); }); function hideHolder() { $('.place-holder').hide(); } function showHolder() { if($('.name-field').val() == '') { $('.place-holder').show() } } $('.name-field').focus(hideHolder); $('.name-field').blur(showHolder); $('.place-holder').click(function () { $('.name-field').trigger('focus'); }); }); } } Thank you for your help. :-) I would like to have a popup in front at all times, for instruction purpose, even when user doing something in back page, such as type something, select and change to new page, etc. This popup can only be closed by either click at "Close" button or "X" at top right corner. I have to create a mock up page with a popup that reopens every time you close it. Can someone explain to me how to do this?
I have merged two scripts to make a popup that comes up even if blocked, and is for first time visitor only (cookie). The problem is that the way I'm doing it, it might show one or more times to the visitor. I don't want that because it will be irritating and this is a high-priority client. I'm posting the whole script because I think the problem is calling the popup before checking the cookie, but not sure how to rearrange things. Also, I did search and found some good dhtml stuff but don't want to rewrite. This was supposed to be done last night so if I can fine tune this for now, I'll have time to rewrite something better (or at least play around with another script). Also, the popup refuses to come up in IE - I have IE6, but I detest IE and their site doesn't even load in it so whatever. I tested in FFox3, Opera 10 and Safari and it seems to work but like I say because of the onclick - it will load at any click until the user goes to a different page. I added a refresh in there but it just made things worse - too much going on for the user at that point. Thanks for any suggestions. I hope I've used the right tags for this. I've highlighted the stuff at the bottom that I think is where I need the most help. Here is the code: // added for popup -kk var expDays = 100; // number of days the cookie should last //var page = "only-popup-once.html"; //var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes"; var newwin = null; function openwin() { // window.location.reload(); var url = "/NEWSLETTER.html" try { if (newwin != null && typeof(newwin.location.href) != 'undefined') { newwin.location.href = url; } else { newwin = open(url, "Subscribe", "height=390,width=545,screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fulls creen=0,location=0,menubar=0,resizable=yes,scrollbars=0,status=0,toolbar=0"); } newwin.focus(); } catch (e) { newwin = open(url, "Subscribe", "height=390,width=520,screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fulls creen=0,location=0,menubar=0,resizable=yes,scrollbars=0,status=0,toolbar=0"); newwin.focus() } } function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } var exp = new Date(); exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); function amt(){ var count = GetCookie('count') if(count == null) { SetCookie('count','1') return 1 } else { var newcount = parseInt(count) + 1; DeleteCookie('count') SetCookie('count',newcount,exp) return count } } function getCookieVal(offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } function checkCount() { var count = GetCookie('count'); if (count == null) { count=1; SetCookie('count', count, exp); // window.open(page, "", windowprops); window.onclick = openwin; // window.location.reload(); } else { count++; SetCookie('count', count, exp); } } window.onload=checkCount; // end popup -kk Hi, I'm kinda hoping this is possible but haven't found any reference to it... I have a parent page that opens a popup on click that launches a sidebar navigation on the right of the screen and resizes the parent page. What I am wanting to do is create a second popup (approx 250px high) that opens below the navigation (which is only around 600px high) but I have noticed that even when you have no status bar in the popup windows, they can still end up overlapping because of additional tools or plugins that the viewer has in their browser. Is there any way to get the popups to butt up against each other instead of overlapping? More like a relative popup? Any assistance would be appreciated. :-) Hi Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } alert(err-str); here ind==1 is from_time and ind==2 is to_time,i need to validate time as to_time must be always greater than from-time,if condition fails an alert msg should populate.time format is[05:00]as it is in string format im unable to do the validation for it.(ex:from-time=08:00 to-time=07:59 condition fails) thank you. Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that. Code: var err_str=""; function validate_grid(value,id,ind) { if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } hi im using dhtml xgrid where i need to do validation for time ,(from-time and to-time i.e ind==1 and ind==2 ) to-time must be greater than from-time else i need to alert a message to-time must be greater than from-time. can any one send me the code for it time format is[05:00]. Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve I'm not really a Java writer, so I don't know how to do this myself, though I imagine it would be pretty simple. I am looking to add a script to a webpage that allows users to input a time manually, and have it converted to GMT/Zulu time and display the converted time. I have seen a lot of time zone conversion scripts online, but they all just convert whatever the current system time is to another time zone. I am looking for a script that allows users to convert a time and show the zulu time, for times other than the current time. The time zone the inputed local time would be in is +4:30 (Kabul). I don't really care about style or aestehtics, just a simple script I can insert into a web page to have a time input field. The converted output time can appear in another field, a popup bubble, etc, again style isn't really an issue. It's really just to help people in my job who need to know what the GMT/Zulu time was for certain local times after the fact. One would think it shouldn't be that hard to just subtract 4:30 in your head, but apparently it is. Sorry if just asking for code outright like this is frowned upon. This is my first time doing JavaScript I don't what I did wrong here, but the problem its not showing up the current date and time. Code: <script language = "JavaScript" type="text/javascript"> now = new Date(); localtime = now.toString(); utctime = now.GMTString(); document.wite("<b>localtime</b>" + localtime + "</br>"); document.write("<b>utctime</b>" + utctime); </script> This is what supposed to look like I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7 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> 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 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, 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. 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. 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? 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.. |