JavaScript - Creating A Cookie In Javascript Not Working!!! Help!!!
I am creating a cookie that increases a "value" or "integer" by 1 (ie Y+1) every time any page inside my webpage. Any webpage that i put the code into. right now I need it so that when you visit a page with the code it increases the variable or "cookie" (Y) by 1. when Y reaches a certain number, I.E 10, it resets Y to "0" and redirects you to a URL. Please explain where each value would go in any replies. Please make code as simple and as low in file size as possible. I don't need any sort of flexibility, just a simple redirect to a webpage which WILL NOT have the cookie code in it.
EX: when opening the menu of an iPod game it asks you to rate the game, saying remind me later resets the value to "0" and saying rate now, resets to "0" but does not keep counting on the next page. Thanks to all in advance and i hope you completely understood my problem and question! [spoiler] Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script type="text/javascript"> function checkValue() String Y Y=Y+1 if(Y > 9){ alert(Y)} else{ alert(Y)} </script> </head> <body> <form action="Javascript:checkValue()" > <div align="center"> <input name="Logon" type="submit" value="Click Me"/> </div> <script type="text/javascript"> function checkValue() String Y; Y=Y+1; alert(Y); //if(Y > 9){ //alert(Y)} //else{ //alert(Y)} </script> </form> </body> </html> [/spoiler] I did not expect any of the above code to work, completely providing a new code will not surprise me or be a problem. Thanks again in advance! Similar TutorialsHi, i'm not sure this is the right spot for my question ,but i will try. ( sorry if not ) I need to create a script, that sets cookie ,named "something" with a random $value - something(1-500) every time the user refreshes his browser. Something like this : Y.Node.get("#Button1").on("click", function(){ var newValue = "something" + Math.round(Math.random() * Math.PI * 500); Y.Cookie.set("$something", newValue); Y.log("Set cookie '$something' to '" + $something + "'"); But when i refresh the browser the cookie must be with a new Value. I will explain more clearly : I hit Button 1, Activate this script,that sets me the cookie named "something" with a $value for example , something55 I refresh my browser,the same cookie has $value for example something98 Thanks in advance, Regards, Anton P.S. i'm trying to make it work for a few days .so i will be very glad if someone could help me here . I need help in creating a multiple value cookie when the user clicks the Add to cart input button. Here is the portion of code from the html page that creates the inventory item display and the Add to cart button. There are six of these on the page: Code: <div id="inventoryspread"> <div class='productBoxInvUL'> <script type:"text/javascript"> document.write("<img src="+"'"+"images/"+arrImage[0]+"'"+"align='left'/>"+ "<p><br/><span class='invName'>"+arrName[0]+"</span></p>"+ "<p>"+arrDescription[0]+"</p>"+ "<p>Item# "+arrItem[0]+"<br/>"+ "<span class='invPrice'>"+arrPrice[0]+"</p>"); </script> <input type="button" value="Add to Cart" onclick='createCookie("name, value, 7", prompt("cookie created"))' /> </div> And here is a portion of the array that fills it: Code: var arrItem = new Array(); var arrName = new Array(); var arrDescription = new Array(); var arrPrice = new Array(); var arrImage = new Array(); arrItem[0]= "FE100"; arrName[0]= "Blacktop Jazzmaster"; arrDescription[0]= "Monster dual-bucker tone. Vintage style alnico humbucking pickup, single coil, skirted black amp knobs, and 3-way toggle switch. Alder body, Maple neck, Rosewood fretboard, 21 medium jumbo frets, gloss urethane finish and nickel/chrome hardware."; arrPrice[0]= "$699.00"; arrImage[0]= "FE100.png"; arrItem[1]= "FE200"; arrName[1]= "Roland-Ready Stratocaster"; arrDescription[1]= "Time-tested Fender tone, timeless styling, 3 single-coil pickups, synchronized tremolo, high-mass bridge block, shielded body cavities and medium jumbo frets. Built-in Roland GK-2A pickup system, tinted neck, parchment pickguard and control knobs, and a '70s-style logo."; arrPrice[1]= "$1,019.00"; arrImage[1]= "FE200.png"; arrItem[2]= "FA100"; arrName[2]= "CD220SCE Exotics "; arrDescription[2]= "Exotic and beautiful with rich tone, laminated burl ash back and sides, with a solid spruce top. Fender-designed dreadnought body, X-bracing, and die-cast tuners. Cutaway body design with rosewood bridge featuring a compensated bone nut"; arrPrice[2]= "$629.00"; arrImage[2]= "FA100.png"; arrItem[3]= "FA200"; arrName[3]= "Dick Dale Mailbu SCE"; arrDescription[3]= "Thin folk body design, laminated spruce top, laminated mahogany back and sides, scalloped X-bracing providing well balanced tone. Maple neck, rosewood compensated bridge and fretboard, vintage-style Fender tuners, and a surfin' red paint job on the top and back"; arrPrice[3]= "$849.00"; arrImage[3]= "FA200.png"; arrItem[4]= "FB100"; arrName[4]= "Standard Precision Bass"; arrDescription[4]= "Sound, look, and feel today's bass players demand. Classic P-Bass old-school design. Contemporary features and refinements. Alder body and a split single-coil pickup, this classic electric bass guitar lives up to its Fender legacy."; arrPrice[4]= "$579.00"; arrImage[4]= "FB100.png"; arrItem[5]= "FB200"; arrName[5]= "Roger Waters Signature Precision Bass"; arrDescription[5]= "Tastefully tailored, black-on-black color scheme, Seymour Duncan Basslines SPB-3 Quarter-Pound split-coil Precision Bass pickup, knurled black control knobs, brass nut, black bridge and strap buttons, vintage '70s-style open-gear chrome tuners."; arrPrice[5]= "$1,199.00"; arrImage[5]= "FB200.png"; arrItem[6]= "GE100"; arrName[6]= "Firebird X Limited Edition"; arrDescription[6]= "Turbo-charged Pure-Analog engine. Hand-applied and unique high-end wood finish. Beautiful, historical and yet contemporary and unique. Limited run of just 1,800 units. It is sure to become a collector classic."; arrPrice[6]= "$5,569.00"; arrImage[6]= "GE100.png"; The cookie only needs to include the Item#, Name and Price of each item to populate a shopping cart page. This is only a small student project and is client side only using javascript. Thank you for any help we can get on this. The guy who originally coded this is no longer with us and we can't seem to figure out why this code isn't working. Neither of us really know JS. I've messed with jQuery more than I've messed with straight up JS but even that is limited knowledge. Basically this code is supposed to keep track of the left navigation so when it goes to a new page it holds the opened menus open. Here's a snippet of HTML: Code: <ul id="leftnav"> <li class="widthT1"> <div id="2042-open" style="display: none;"><a href="javascript:treeToggle('2042', 'open', '/JobSeekers/Recently_Unemployed/index.aspx');" class="orangePlus">Recently Unemployed</a></div> <div id="2042-close" style="margin-bottom:10px;"><a href="javascript:treeToggle('2042', 'close');" class="orangeMinus">Recently Unemployed</a> <!--<div class="fix1"><hr class="grey1HR"/></div>--> <ul class="fix4"> <li> <div id="2063-open" style="display: none;"><a href="javascript:treeToggle('2063', 'open', '/JobSeekers/Recently_Unemployed/Apply_for_Unemployment_Insurance_Benefits/index.aspx');" class="orangePlusGT2">Apply for Unemployment Insurance Benefits</a></div> <div id="2063-close"><a href="javascript:treeToggle('2063', 'close');" class="orangeMinusGT2">Apply for Unemployment Insurance Benefits</a> <!--<div class="fix2"><hr class="grey2HR"/></div>--> <ul> The above is repeated but that should be enough to show you what it's doing? Here's the JS: Code: function getTreeStateArray() { var empty = new Array(); var soc = document.cookie.indexOf("treestate="); if(soc != -1) { var eoc = document.cookie.indexOf("-", soc); if(eoc == -1) eoc = document.cookie.length; return(unescape(document.cookie.substring(soc+10, eoc)).split("-")); } return(empty); } function setTreeStateArray(treeState) { document.cookie = "treestate=" + escape(treeState.join("-")); } function restoreTreeState(treeID) { var treestate = getTreeStateArray(); var i, j, treeNodeName, treeElements; treeElements = document.getElementById(treeID).getElementsByTagName("div"); for(i = 0; i < treeElements.length; i++) { var sosuffix = treeElements[i].id.indexOf('-close'); if(sosuffix == -1) sosoffix = treeElements[i].id.indexOf('-open'); if(sosuffix != -1) { var nodeName = treeElements[i].id.substring(0, sosuffix); var found = false; for(j = 0; j < treestate.length; j++) { if(treestate[j] == nodeName) found = true; } if(found == true) { document.getElementById(nodeName + '-open').style.display = 'none'; document.getElementById(nodeName + '-close').style.display = 'block'; } else { document.getElementById(nodeName + '-open').style.display = 'block'; document.getElementById(nodeName + '-close').style.display = 'none'; } } } } function removeNodeFromTreeState(nodeName) { var treestate = getTreeStateArray(); var newTreeState = new Array(); var i, treeNodeName; for(i = 0; i < treestate.length; i++) { treeNodeName = treestate[i]; if(treeNodeName != nodeName) newTreeState.push(treeNodeName); } setTreeStateArray(newTreeState); } function addNodeToTreeState(nodeName) { var treestate = getTreeStateArray(); var newTreeState = new Array(); var i, treeNodeName; for(i = 0; i < treestate.length; i++) { treeNodeName = treestate[i]; if(treeNodeName == nodeName) return; newTreeState.push(treeNodeName); } newTreeState.push(nodeName); setTreeStateArray(newTreeState); } function treeToggle(treeNodeName, treeNodeState, followLink) { if(treeNodeState == 'open') { addNodeToTreeState(treeNodeName); document.getElementById(treeNodeName + '-open').style.display = 'none'; document.getElementById(treeNodeName + '-close').style.display = 'block'; if(typeof(followLink) != 'undefined') window.location.href = followLink; } else { removeNodeFromTreeState(treeNodeName); document.getElementById(treeNodeName + '-open').style.display = 'block'; document.getElementById(treeNodeName + '-close').style.display = 'none'; } } What happens is it remembers the first thing you click on, but nothing more. We looked at the cookie value and it seems to be right. 4digit number followed by - followed by 4 more digits etc etc (0000-0001-0002 etc) If anyone could help that would be wonderful. Thanks for any and all help, Justin anyone can help me in cookie ? i couldn't get it to work. My objective is when i click the submit button in the guestbook page, the cookie will then capture just the 'name' and display it out in thankyou page. guestbook page var seconds = 0; function startTimer() { window.setInterval("updateTime()", 1000); } function updateTime() { seconds++; soFar.innerText = seconds; } function validate_email(field) { with (field) { apos=value.indexOf("@"); //find the position of the @ character dotpos=value.lastIndexOf(".");// find the last position of the . character if (apos<1||dotpos-apos<2) { alert("Not a valid e-mail address!"); return false; } } } function validate_length(field) { with(field) { if (value.length == 0) { alert("Please fill up the column!"); return false; } } } function getCookie(NameOfCookie){ if (document.cookie.length > 0) { begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1){ begin += NameOfCookie.length+1; end = document.cookie.indexOf(";",begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null; } function setCookie(NameOfCookie, value, expiredays) { var ExpireDate = new Date (); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 *3600 * 1000)); document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null)?"" : ";expires=" + ExpireDate.toGMTString()); } function delCookie (NameOfCookie){ if (getCookie(NameOfCookie)){ document.cookie = NameOfCookie + "=" + "; expires=Thu,01-JAN-70 00:00:01 GMT"; } } function validate_form(thisform) { with (thisform) { if (validate_length(yourname) == false) { yourname.focus(); return false; } if (validate_length(email)==false || validate_email(email)==false) { email.focus(); return false; } if ( ( document.contact_my.gender[0].checked == false ) && ( document.contact_my.gender[1].checked == false ) ) { alert ( "Please choose your Gender: Male or Female" ); valid = false; contact_my.focus(); return false; } } } </script> <form name="contact_my" action="thankyou.html" onSubmit="return validate_form(this)" && onClick="setCookie" method="post" > <input type="submit" value="Submit"> <input type="reset" value="Reset form" onClick="delCookie( 'username' )"> thankyou page function getCookie(NameOfCookie){ if (document.cookie.length > 0) { begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1){ begin += NameOfCookie.length+1; end = document.cookie.indexOf(";",begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null; } function setCookie(NameOfCookie, value, expiredays) { var ExpireDate = new Date (); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 *3600 * 1000)); document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null)?"" : ";expires=" + ExpireDate.toGMTString()); } function DoTheCookieStuff() { username=getCookie ('username'); if ( username!=null ) {document.writeln ('Hi there '+username+' - Good to see you again!')} } Hi i used cookies to store data using java script with 2 calculators, but there is a 3rd calculator that the cookies arent storing, can someone help me figure out where to implement the script?
Hey guys, i'm trying to incorporate cookies with the website i'm working on. I've looked at tutorials where they just hand you the code and say "get on with it", this leaves me in the lurch while trying to debug it... so the question is are there any good javascript cookie tutorials that will "explain what the heck this does?" Thanks Al. Hey guys, Here is my question: Is it possible to extract a cookie inside a textarea? For example, I am building a very basic shopping cart in Javascript, with "Add to Cart" buttons listed for each item. As the "Add to Cart" button is pressed, a cookie is created. There is a link in which you can click with "Review Order", which consists of a textarea that displays the items that you have 'purchased'. I am trying to get the value of the cookie to be extracted into this textarea, however I am not sure if this is possible. Thanks hello everybody, here I'm asking for help again. sorry for that in advance. anyhow, I have the following code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link type="text/css" media="screen" rel="stylesheet" href="colorbox.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="../colorbox/jquery.colorbox.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".example7").colorbox({width:"300px", height:"500px", iframe:true, open: true}); }); </script> </head> <body onload="example7();"> <a class='example7' href="tofes.html"></a> teststestestest </body> </html> I want the lightbox window open only once a day for every unique visitor on my website. I understand I should use some sort of cookie implented, but I dont really understand how to. Thanks in advance, daniel. I have been looking all over the web for a solution, because my website displays funky in safari. To fix this i figured i'd tell users that if they are using safari, then using javascript, i could tell them a message. Originally i tried detecting safari then displaying a message. But i couldn't ever find a browser detection for safari. So i thought wait.... If i could: 1. get a javascript alert saying my message. 2. time that message alert frequency by a session, say 10 days? or even every browser session... Then i could solve my problem. However i can't figure out any of this. So if anybody would be willing to help, i'd be very grateful. Hi all Experts I am in a need of a simple javascript script that can verify if a cokie exist If it exist: (replace the below and show) You already upgraded. If not exist: I would like it to show: You account is not upgraded yet Please upgrade your account, click here to upgrade<br> <center><A href="url"><img src="picture"></center> also need seperate script to set the cokie Hope u understand what I want thank you Hi, I have a website where the user can navigate different categories by tab. The problem is, when they're on a tab other than the default one and they refresh the page or click to another page, it puts them back on the first tab. I know this can be solved by using a session cookie of some type, I just need some help on implementing it into my site. http://www.thatswhyimbroke.com/ - so you can see what i'm talking about. If you look at the different tabs: Price High, price low, food & drink, etc. I want the user to be able to go to one of those, click to page 2 or refresh, and still be on that tab. Any help would be much appreciated! I need some help for University cousework that has been sent and I hope someone here can help. I need to create a cookie (easy enough) and then populate that cookie with a word that is selected when you click a certain image. Imagine you have image1.jpg and image2.jpg when a user selects image1.jpg the cookie needs to store image1 and load page2.html If the user selects image2, then page2.html still needs to load but store the word image2 in the cookie. On the next page, the cookie is loaded and the page needs to load the css file associated with that word example: image1 = firstcss.css image2 = secondcss.css Is this possible? Thank you for all your help Hi all, im trying to select certain elements from on screen and set the style of a div to over lap it. Code: $("body *").each(function(){ if($(this).attr("rel")!="nbta"){ alert("#div" + z + " style: " + "display:block; width:" + $(this).width() + "px; height:" + $(this).height() + "px; position:absolute; top:" + $(this).position().top + "px; left:" + $(this).position().left + "px; border: 1px solid red; z-index:" + $(this).parentNumber() + ";"); $("#div" + z).attr("style", "display:block; width:" + $(this).width() + "; height:" + $(this).height() + "; position:absolute; top:" + $(this).position().top + "; left:" + $(this).position().left + "; border: 1px solid red; z-index:" + $(this).parentNumber() + ";"); z++; } }); Code: <p id="fooBar">dfgdsfdsfdsf1111</p> <p id="fooBar2">dfgdsfdssdsdfdsf222</p> <p id="fooBar3">dfgdsfdsfdsf333</p> <p id="fooBar4">dfgdsfdsfdsf444</p> <div id="div1" style="display:none" rel="nbta"> </div> <div id="div2" style="display:none" rel="nbta"> </div> <div id="div3" style="display:none" rel="nbta"> </div> <div id="div4" style="display:none" rel="nbta"> </div> seems easy enough and the results are showing corrent i just cant seem to get it to display! Hello, Could anyone help me? I'm looking for a script that remembers, re-sets, and can set to the previous state the show or hide behavior of a layer upon return to the page. I have an image gallery that's in 3 categories: wedding, bridal shower and save-the-dates. When viewing an image in the bridal shower or save-the date galleries and I press on the link I created titled "Back to Gallery" it does not return me back to the Bridal Shower or Save-the-dates gallery (whichever I'm in) it returns me to the main Invitations gallery page. So bascially I'm looking for a script that will write to a cookie what layers are shown and what are hidden so when you return it reads the cookie and displays the last layers you had showing before leaving the page. Hi everyone, I am using a jQuery cookie script to set the cookie of some elements on my website. One of the problems is that I need the cookie to not expire after one day, I need it to expire after a while (I'm going to start off with a year). Here's my script, the red part is what I've been editing. Code: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secu true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000 * 365)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; I hope I have this post in the right place! Any help would be very much appreciated... I have a feature on my website that allows users to choose the website background (using alternate css sheets) and then uses an externally linked javascript file to store the background choice as a cookie so it is consistent throughout the website. This works perfectly locally (i.e. when previewing my website on my computer) but now it is uploaded to my host it doesn't appear to be working. (with the same browser) My javascript is he http://www. b r p - e n v .com/javascript/backgroundchange.js (with no spaces) The website that the javascript file is linked to is http://www. b r p - e n v .com (with no spaces) In the head I have: <script type="text/javascript" src="../javascript/backgroundchange.js"></script> ...then I have: <body onload="set_style_from_cookie()"> ...and for users to choose which background: <form> <input type="image" src="../images/white-background-thumb.jpg" onclick="switch_style('bg1');return false;" name="theme" value="White" id="bg1"> etc... </form> My problem is: The background reverts back to the default when moving to a different page. This would indicate that the background choice is not being saved in cookies. But this works locally! I have tried putting the javascript directly onto each page but I still had the same problem. I hope someone can help, I will be so grateful if I can get this to work. Many thanks indeed! I basically have a property website with different types of properties, e.g. detached houses, semi detached houses. and I want to create a filter so when you click 'detached houses' only detached houses are shown. Is there any tutorials you can point me to, would be appreciated. This is what i have so far.. Code: <div id="main"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b> <br /> <span class="dh"><b><u>Detached Houses</u></b></span> <br /> <span class="dh"><b><u>Semi-detached houses</u></b></span> <br /> <span class="dh"><b><u>Terraced houses</u></b></span> <br /> <br /> <b><u>Flats / Apartments</u></b> </p></div></td> <td><div id="info1"><a href="#"><img src="cutouts/forsale/pinfo1.jpg" alt=""/></a></div></td> </tr> </table> <div id="info2"><a href="#"><img src="cutouts/forsale/pinfo2.jpg" alt=""/></a></div> <div id="info3"><a href="#"><img src="cutouts/forsale/pinfo3.jpg" alt=""/></a></div> <div id="info4"><a href="#"><img src="cutouts/forsale/pinfo4.jpg" alt=""/></a></div> <script type="text/javascript"> var properties = {$properties_json}; // very simple getter method that uses a single key-value pair. var selectProperties(k, v) { var rv = []; for (var i in properties) { if (properties[i][k] == v) { rv.push(properties[i]); } } return rv; } // selectProperties() </script> </div> Below is a javascript function from my website that loops through nodes in an XML file retrieving certain information about those who joined in the current month/year. The part in red creates a link which when clicked runs a function called show() with the relevant i variable value e.g. show(2) for the second node if that is relevant. Anyway the red part works in Chrome but not Internet Explorer (surprise surprise). I did some research which says that .setattribute is not allowed in IE. How can I change the red code to create links for the relevant records which works in IE? Thank you for your help Code: function displaymember() { var d = new Date(); var curr_month = d.getMonth(); curr_month++; if (curr_month < 10) curr_month = "0" + curr_month; var curr_year = d.getFullYear(); for (i = 0; i < x.length; i++) { membershipstatus = (x[i].getElementsByTagName("membership_status")[0].childNodes[0].nodeValue); name = (x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue); body = (x[i].getElementsByTagName("body_type")[0].childNodes[0].nodeValue); ethnicity = (x[i].getElementsByTagName("ethnicity")[0].childNodes[0].nodeValue); sex = (x[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue); seeking = (x[i].getElementsByTagName("seeking")[0].childNodes[0].nodeValue); date = (x[i].getElementsByTagName("date_joined")[0]); month = (date.getElementsByTagName("month")[0].childNodes[0].nodeValue); year = (date.getElementsByTagName("year")[0].childNodes[0].nodeValue); newa = document.createElement("a"); aIdName = "my" + i + "a"; ahref = "#"; aclick = "show(" + i + ")"; newa.setAttribute("id", aIdName); newa.setAttribute("href", ahref); newa.setAttribute("onclick", aclick); newa.innerHTML = name + " | " + body + " " + ethnicity + " " + sex + " with " + membershipstatus + " membership seeks " + seeking + "<br/>"; if (curr_month == month && curr_year == year) { document.getElementById("member").appendChild(newa); } } } hereis the html file and javascripton click of this button a html ***************************** <table class=matcolor id=topnav cellspacing=0 cellpadding=0 width=550 border=0 bgcolor="#FFCCCC"> <tbody> <tr align=middle> <td id=menu1 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Desk Top Publishing </font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu2 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Transcription</font></div> </td> <td width=1 bgcolor=#ff9900 class="mat"></td> <td id=menu3 onMouseOver="this.className='mPrimaryOn';showmenu(this);" onClick="this.document.location.href=''" onMouseOut="this.className='mPrimaryOff';hidemenu(this);" class="mat" height="20"> <div align="center"><font color="#FF0000">Accounts Processing </font></div> </td> </tr> </tbody> </table> ***************************************** <script language=JavaScript> ix = document.getElementById('tblmenu1').getBoundingClientRect(); new ypSlideOutMenu("menu1", "right",ix.left + ix.right ,ix.bottom + 10); </script> **any thing i have to alter to work in firefox please help |