JavaScript - Saving Audio State In Cookie, Only Works Properly In Chrome.
Hey all,
I have this code, that saves the "play" or "pause" audio-tag state in a cookie for recognizing on different pages. This code only works properly in Chrome, but not in other browsers. In IE, it doesn't save/recognize the cookies, apparently. And in Firefox, I don't even get the audio to play. Code: $(document).ready(function(){ if ($.cookie("audioState") == "pause") { $("p#sound audio").get(0).pause(); $("p#sound span#sound-icon").css({backgroundPosition: "0 -37px"}); } else if ($.cookie("audioState") == "play") { $("p#sound audio").get(0).play(); $("p#sound span#sound-icon").css({backgroundPosition: "0 0"}); } $("p#sound").click(function() { var song = $(this).find("audio").get(0); var soundIcon = $(this).find("span#sound-icon"); if (song.paused) { song.play(); soundIcon.css({backgroundPosition: "0 0"}).hide().stop(1, 1).fadeIn(500); $.cookie("audioState", "play"); } else { song.pause(); soundIcon.css({backgroundPosition: "0 -37px"}).hide().stop(1, 1).fadeIn(500); $.cookie("audioState", "pause"); } }); }); Code: <p id="sound">MUSIC <span id="sound-icon"></span> <audio autoplay="autoplay" loop="loop"> <source src="audio/Breather2000-Afterlife.ogg" type="audio/ogg" /> <source src="audio/Breather2000-Afterlife.mp3" type="audio/mp3" /> Your browser does not support the audio tag. </audio> </p> What am I doing wrong? Thanks already! Similar TutorialsThe 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 I have a form that passes values to a next step. It has two sub divs that show depending on what's selected from the dropdowns in the top two divs. I'm trying to keep the selected sub divs open if the user hits previous step. The divs stay open in FF but not in IE. Any ideas? dropdowns Code: <table border="0" cellspacing="0" cellpadding="2"> <tr valign="top"> <td align="right">Morning:</td> <td><select name="wcsave_10_msession" id="wcsave_10_msession" size="1" onblur="CheckField(this.form,this,'');" onchange="display1(this,'Concurrent sessions 1-6');"> <option value="" selected="selected">Choose one</option> <option value="Mastery session 1 - Computer Lab: Searching Essentials"> <strong>Mastery session 1</strong> - Computer Lab: Searching Essentials</option> <option value="Concurrent sessions 1-6">Concurrent sessions 1-6</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Concurrent sessions 1-6" style="display: none;"> <table class="special"> <tr valign="top"> <td>Choose a session for each time slot.<br /> (9:15 a.m. - 10:15 a.m.)<br /><select name="wcsave_10_session_mconc1" id="wcsave_10_session_mconc1"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 1 - IRB 101 for Research Nurses">Concurrent session 1 - IRB 101 for Research Nurses</option> <option value="Concurrent session 2 - A Research Poster Contest as a Tool to Learn About Research/EBP">Concurrent session 2 - A Research Poster Contest as a Tool to Learn About Research/EBP</option> <option value="Concurrent session 3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature">Concurrent session 3 - Beginning the EBP Journey: Evaluating and Synthesizing the Literature</option> </select> </td> </tr> <tr valign="top"> <td>(10:30 a.m. - 11:30 a.m.)<br /><select name="wcsave_10_session_mconc2" id="wcsave_10_session_mconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 4 - Making Sense of Statistics When Reading Research">Concurrent session 4 - Making Sense of Statistics When Reading Research</option> <option value="Concurrent session 5 - Original Research Presentations">Concurrent session 5 - <em>Original Research Presentations</em></option> <option value="Concurrent session 6 - IRB Considerations with Vulnerable Populations">Concurrent session 6 - IRB Considerations with Vulnerable Populations</option> </select> </td> </tr> </table> </div> </td> </tr> <tr valign="top"> <td colspan="2"> </td> </tr> <tr valign="top"> <td align="right">Afternoon:</td> <td><select name="wcsave_10_asession" id="wcsave_10_asession" size="1" onblur="CheckField(this.form,this,'');" onchange="display2(this,'Concurrent sessions 7-12');"><!--showDiv(this.value)--> <option value="" selected="selected">Choose one</option> <option value="Mastery session 2 - Beyond the Basics of Searching!"><strong>Mastery session 2</strong> - Beyond the Basics of Searching!</option> <option value="Concurrent sessions 7-12">Concurrent sessions 7-12</option> </select> </td> </tr> <tr valign="top"> <td> </td> <td> <div id="Concurrent sessions 7-12" class="hiddenDiv"> <table class="special"> <tr valign="top"> <td>Choose a session for each time slot.<br /> (1:45 p.m. - 2:45 p.m.)<br /><select name="wcsave_10_session_aconc1" id="wcsave_10_session_aconc1"> <option value="" selected="selected">Choose one</option> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 7 - EBP Protocols">Concurrent session 7 - EBP Protocols</option> <option value="Concurrent session 8 - Writing for Publication">Concurrent session 8 - Writing for Publication</option> <option value="Concurrent session 9 - Original Research Presentations">Concurrent session 9 - Original Research Presentations</option> </select> </td> </tr> <tr valign="top"> <td>(3:00 p.m. - 4:00 p.m.)<br /><select name="wcsave_10_session_aconc2" id="wcsave_10_session_aconc2"> <option value="" selected="selected">Choose one</option> <option value="Concurrent session 10 - Writing a Research Question Using PICO">Concurrent session 10 - Writing a Research Question Using PICO</option> <option value="Concurrent session 11 - EBP Project Presentations">Concurrent session 11 - EBP Project Presentations</option> <option value="Concurrent session 12 - The Role of the Research Facilitator">Concurrent session 12 - The Role of the Research Facilitators</option> </select> </td> </tr> </table> </div> </td> </tr> </table> javascript: Code: var lastDiv = ""; function showDiv(divName) { var items = document.getElementById('wc_addItem_ADV'); var form = document.getElementById('webcredit'); var total = document.getElementById('Total'); var amount = document.getElementById('amount'); // set checkboxes to 0 for (var i = 0; i < form.elements.length; i++ ) { if (form.elements[i].type == 'checkbox') { form.elements[i].checked = false; document.getElementById(form.elements[i].id).value = "0"; } } total.value = ''; amount.value= ''; // hide last div if (lastDiv) {document.getElementById(lastDiv).className = "hiddenDiv";} //if value of the box is not nothing and an object with that name exists, then change the class if (divName && document.getElementById(divName)) { document.getElementById(divName).className = "visibleDiv"; lastDiv = divName; } } function showInitialDiv() { var selBox = document.getElementById('wcsave_10_session_mconc1'); if (selBox == undefined || selBox == null) return; var val = selBox.options[selBox.selectedIndex].value; if (val == null || val == '') return; showDiv(val); } I only call one of the sub div ID's but it seems to work in FF with no errors. Everything is called with: Code: <body onload="showInitialDiv();"> I have an "animated slideshow" of 29 jpeg images on a page created using Javascript. It works fine in Internet Explorer and Firefox but not Safari or Chrome. The jpeg files names are 01.jpg through to 29.jpg. Here below is the code in the header and the body. There is an error in there somewhe <html> <head> <title>My webpage</title> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <SCRIPT language="JavaScript" type="text/JavaScript"> <!-- var speed=1333; var counter = 1; function rollPics() { document.display.src=counter+".jpg"; //Display image "counter".jpg counter ++; // Add 1 to counter if (counter>29) { // If counter is greater than 29 images then reset it counter=1 } } <!-- END --> </SCRIPT> </head> <body> <center> <table> <tr><td> <IMG NAME="display" SRC="1.jpg" onLoad="setTimeout('rollPics()',1333)"> </td></tr> </table> </center> </body> </html> Go figure huh??? Anyways I have a script a co-worker wrote and it works in FF and Chrome but IE will not work. Get's a 'activeTab' is null or not an object error, I checked for commas and fixed a semi-colon that was missing in two spots but not change in IE. Anyone willing to throw me a bone? code below: Code: <table class="tan-header rounded-box" style="padding:0px;border:0px;width:560px" cellspacing=0 cellpadding=0> <tr class="headerrow"> <td class="main"> <div style="font-weight:bold;padding-top:4px;"> <span ID="Sample Pricing _show" class="arrow-box" style="display:none;"><a href="javascript:Expand('Sample Pricing ');"> <img alt="Click arrow to expand this panel" src="images/right.png" border=0 align="absmiddle"></a></span> <span ID="Sample Pricing _hide" class="arrow-box"><a href="javascript:Contract('Sample Pricing ');"> <img alt="Click arrow to collapse this panel" src="images/down.png" border=0 align="absmiddle"></a></span> Sample Pricing </div> </td> <td class="end"></td> </tr> <tr class="contentrow"> <td class="main"> <div id="Sample Pricing "> <p><em>Based on the following spec's: </em></p> <ul> <li>8.5 x 11 </li> <li>70# high quality opaque paper</li> </ul> <p align="center"> </p> <div align="center"> <table id="pricing_table_tabs"> <th> <td id="option1" class="active_pricing_table_tab">Option 1</td> <td id="option2" class="">Option 2</td> </th> </table> <table width="494" border="1" id="pricing_table1" class="active_table"> <tr> <th width="80" height="30" scope="col">Quantity</th> <th width="95" scope="col">1 Color </th> <th width="95" scope="col">2 Colors</th> <th width="95" scope="col">4 Colors</th> <th width="95" scope="col"> </th> </tr> <tr> <td><div align="center">250</div></td> <td><div align="center">$197.69</div></td> <td><div align="center">$221.58</div></td> <td><div align="center">$420.26</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">500</div></td> <td><div align="center">$210.78</div></td> <td><div align="center">$233.79</div></td> <td><div align="center">$434.75</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">1000</div></td> <td><div align="center">$238.92</div></td> <td><div align="center">$262.30</div></td> <td><div align="center">$446.18</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">2000</div></td> <td><div align="center">$298.84</div></td> <td><div align="center">$316.78</div></td> <td><div align="center">$481.68</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">2500</div></td> <td><div align="center">$328.26</div></td> <td><div align="center">$345.55</div></td> <td><div align="center">$499.10</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">3000</div></td> <td><div align="center">$358.50</div></td> <td><div align="center">$373.05</div></td> <td><div align="center">$513.08</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">4000</div></td> <td><div align="center">$416.68</div></td> <td><div align="center">$430.29</div></td> <td><div align="center">$548.58</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">5000</div></td> <td><div align="center">$476.63</div></td> <td><div align="center">$485.45</div></td> <td><div align="center">$585.15</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">10000</div></td> <td><div align="center">$713.26</div></td> <td><div align="center">$758.94</div></td> <td><div align="center">$751.91</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">15000</div></td> <td><div align="center">$879.51</div></td> <td><div align="center">$925.01</div></td> <td><div align="center">$919.47</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">20000</div></td> <td><div align="center">$1041.92</div></td> <td><div align="center">$1092.30</div></td> <td><div align="center">$1085.25</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> </table> <table width="494" border="1" id="pricing_table2" class="inactive_table"> <tr> <th width="80" height="30" scope="col">Quantity</th> <th width="95" scope="col">1 Color </th> <th width="95" scope="col">2 Colors</th> <th width="95" scope="col">4 Colors</th> <th width="95" scope="col"> </th> </tr> <tr> <td><div align="center">250</div></td> <td><div align="center">$1</div></td> <td><div align="center">$2</div></td> <td><div align="center">$4</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">500</div></td> <td><div align="center">$2</div></td> <td><div align="center">$2</div></td> <td><div align="center">$4</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">1000</div></td> <td><div align="center">$238.92</div></td> <td><div align="center">$262.30</div></td> <td><div align="center">$446.18</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">2000</div></td> <td><div align="center">$298.84</div></td> <td><div align="center">$316.78</div></td> <td><div align="center">$481.68</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">2500</div></td> <td><div align="center">$328.26</div></td> <td><div align="center">$345.55</div></td> <td><div align="center">$499.10</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">3000</div></td> <td><div align="center">$358.50</div></td> <td><div align="center">$373.05</div></td> <td><div align="center">$513.08</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">4000</div></td> <td><div align="center">$416.68</div></td> <td><div align="center">$430.29</div></td> <td><div align="center">$548.58</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">5000</div></td> <td><div align="center">$476.63</div></td> <td><div align="center">$485.45</div></td> <td><div align="center">$585.15</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">10000</div></td> <td><div align="center">$713.26</div></td> <td><div align="center">$758.94</div></td> <td><div align="center">$751.91</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">15000</div></td> <td><div align="center">$879.51</div></td> <td><div align="center">$925.01</div></td> <td><div align="center">$919.47</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> <tr> <td><div align="center">20000</div></td> <td><div align="center">$1041.92</div></td> <td><div align="center">$1092.30</div></td> <td><div align="center">$1085.25</div></td> <td><div align="center"><a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Place_An_Order/form.mdl&FORM_Form_ID=15221">buy now</a></div></td> </tr> </table> </div> <p align="center"> </p> <p align="center"><strong>Can't find what you are looking for - <a href="https://www.secured-site6.com/printcenter/index.iml?mdl=Request_Estimate/form.mdl&FORM_Form_ID=42195">click here</a> to request a custom quote. </strong></p> </body> </html> </div> <div ID="Sample Pricing _instr" class="detail" style="display:none"> (Click the triangle above to expand this panel.) </div> </td> <td class="end"></td> </tr> <tr class="footerrow"> <td class="main"></td> <td class="end"></td> </tr> </table> <br> <style> #pricing_table_tabs{ border-collapse: collapse; } #pricing_table_tabs td{ border: 2px solid #ccc; padding: 5px; font-size:1.2em; font-weight:bold; } #pricing_table_tabs td:hover{ cursor: pointer; } .active_pricing_table_tab{ background-color: black; border-style: inset; color:white; } .active_table{display:block;} .inactive_table{display:none;} </style> <script language="javascript" type="text/javascript"> var activeTab = document.getElementById("option1"); var activePricingTable = document.getElementById("pricing_table1"); function activateTab() { if(activeTab) { activeTab.className = ""; activeTab = document.getElementById(this.id); activeTab.className = "active_pricing_table_tab"; activatePricingTable(activeTab.id); } else { activeTab = document.getElementById(this.id); activeTab.className = "active_pricing_table_tab"; activatePricingTable(activeTab.id); } } function activatePricingTable(activeTabId) { if(activePricingTable) { activePricingTable.className = "inactive_table"; activePricingTable = document.getElementById("pricing_table" + activeTabId.charAt(activeTabId.length - 1)); activePricingTable.className = "active_table"; } else { activePricingTable = document.getElementById("pricing_table" + activeTabId.charAt(activeTabId.length - 1)); activePricingTable.className = "active_table"; } } for(i=1; i<=2; i++){ if (window.addEventListener){ document.getElementById("option" + i).addEventListener("click", activateTab, false); } else{ document.getElementById("option" + i).attachEvent("onclick", activateTab); } } </script> I built a registration and edit profile form using java to show or hide drop down selectors dependent on parent selection. I'm also using an ajax script to pull the selector values from txt files for the city selector. This works fine in chrome, but will not work in ie or ff. I've also found that the ajax script simply doesn't work in ff at all period even with the formmanager scrip removed. The site is erecoverydev.com. Click on the join now tab to see the registration form, or you can log in with un test and pw test123, then click on edit my page in the left hand menu to view the edit profile form. Here is what's in the head to call these scripts: Code: <script src="/js/FormManager.js"> /**************************************************** * Form Dependency Manager- By Twey- http://www.twey.co.uk * Visit Dynamic Drive for this script and mo http://www.dynamicdrive.com ****************************************************/ </script> <script type="text/javascript"> window.onload = function() { setupDependencies('cbcheckedadminForm', 'weboptions'); //name of form(s). Seperate each with a comma (ie: 'weboptions', 'myotherform' ) }; </script> <script src="/js/request.js"> /**************************************************** * Ajax call to fill city values ****************************************************/ </script> <script> function handleOnChange(dd1) { var idx = dd1.selectedIndex; var val = dd1[idx].text; var par = document.forms["adminForm"]; var parelmts = par.elements; var cb_citysel = parelmts["cb_city"]; var state = val; if (cb_state != "Select state") { var directory = ""+document.location; directory = directory.substr(0, directory.lastIndexOf('/')); Http.get({ url: "./regvalues/" + state + ".txt", callback: fillcb_city, cache: Http.Cache.Get }, [cb_citysel]); } } function fillcb_city(xmlreply, cb_cityelmt) { if (xmlreply.status == Http.Status.OK) { var cb_cityresponse = xmlreply.responseText; var cb_cityar = cb_cityresponse.split("|"); cb_cityelmt.length = 1; cb_cityelmt.length = cb_cityar.length; for (o=1; o < cb_cityar.length; o++) { cb_cityelmt[o].text = cb_cityar[o]; } } else { alert("Cannot handle the Ajax call."); } } </script> Any ideas? I'll post the rest of the script codes in a reply. I'm just starting JavaScript and wrote a quick script for Next/Back buttons for a page showing a family outing on our boat. I proudly uploaded the webpage and emailed it out, but people running IE are unable to use the buttons, they simply do nothing. Here is the .js file, I don't think anything in the HTML or CSS is causing the issue but could post those as well if necessary. Code: var step = 1; //preload images var numImages = 13; var images = new Array( numImages ); var i = 0; for ( i = 0; i < numImages; i++ ) { images[i] = new Image(); images[i].src = "images/boat" + ( i + 1 ) + ".jpg"; } function back() { if( step > 1 ) { step--; } else { step = numImages; } document.images.slide.src = images[step-1].src; } function next() { if( step < numImages ) { step++; } else { step = 1; } document.images.slide.src = images[step-1].src; } function init() { document.getElementById("back").onclick = back; document.getElementById("next").onclick = next; } window.onload = init; I've checked a lot of sites and can't figure this one out. Also, if I'm practicing any bad coding techniques, I'm open to suggestions on that as well hi, i got this javascript function which run perfectly in IE but does not work in Mozilla. Any idea ? function Changed() { var theGridView = document.getElementById('MainContent_GridViewRDR1_Hidden'); var sum = 0; var total = 0; var totalFinal = 0; for (var i = 0; i < theGridView.rows.length; i++) { var csValue = document.getElementById('MainContent_GridViewRDR1_Hidden_CaseTxt_' + i + ''); var pcsValue = document.getElementById('MainContent_GridViewRDR1_Hidden_PCSTxt_' + i + ''); if (csValue.value != '') { if (pcsValue.value != '') { alert('Pcs already have value') document.getElementById('MainContent_GridViewRDR1_Hidden_CaseTxt_' + i + '').innerText = ''; break; } if (isNaN(csValue.value)) { alert('Please enter number') document.getElementById('MainContent_GridViewRDR1_Hidden_TotalPriceTxt_' + i + '').innerText = 0; document.getElementById('MainContent_TextBox1').innerText = 0; document.getElementById('MainContent_GridViewRDR1_Hidden_CaseTxt_' + i + '').innerText = 0; break; } var unitPriceValue = theGridView.rows(i + 1).cells(7).innerText; var unitUOM = theGridView.rows(i + 1).cells(5).innerText; sum = (parseFloat(csValue.value) * parseFloat(unitPriceValue) * parseFloat(unitUOM)).toString(); sum = roundVal(sum); document.getElementById('MainContent_GridViewRDR1_Hidden_TotalPriceTxt_' + i + '').innerText = sum; total += sum; total = roundVal(total); document.getElementById('MainContent_TextBox1').innerText = total; } else { sum = 0; } } total = roundVal(total); totalFinal += total document.getElementById('MainContent_TextBox1').innerText = totalFinal; } The following script grabs a string (*.abc.org, e.g. from &sid=xyz.abc.org) from the current URL and changes it (to ABC:abc.org). Everything works perfectly in IE, but Firefox and Chrome appear to get themselves into an endless loop. When I check the URL, xyz.abc.org has successfully been changed to ABC:abc.org, but the page just seems to keep refreshing over and over. Code: var tomatch = /abc.org/i; var usrString = document.referrer; var is_a_match = tomatch.test(usrString); var newString = document.URL.replace(/[a-z]*\.abc\.org/, "ABC:abc.org"); if (is_a_match) { window.location.replace(newString); } Any suggestions much appreciated. Hey Everyone, I have a simple Java Script function I setup for a pop up that requests a discount code. Works awesome in Chrome, FF and on smart phones... but IE and Safari don't work at all. Here is the code.. This is in my header <script> function passWord1018() { var testV = 1; var pass1 = prompt('Please Enter The Discount Code',' '); while (testV < 3) { if (!pass1) history.go(-1); if (pass1.toLowerCase() == "ultra") { alert('Code Accepted! Press Ok To Be Redirected To The Discounted Price Page'); window.open('discounted101018.aspx'); break; } if (pass1.toLowerCase() == "sexydiscount") { alert('Code Accepted! Press Ok To Be Redirected To The Discounted Price Page'); window.open('discounted201018.aspx'); break; } testV+=1; var pass1 = prompt('Code Denied - Code Incorrect, Please Try Again.','Code'); } if (pass1.toLowerCase()!="password" & testV ==3) history.go(-1); return " "; } </script> This is in the body <center> <form> <br /> <input type="button" value="Enter Discount Code" onclick="passWord1018()" /> </form> </center> I found on another site where someone mentioned the <center> tags are not used anymore, but i tried removing those and still nothing... Any insight would be helpful...Thanks Jason Can anyone tell me why the following works in IE but not the other browsers? It's the "Select category..." jump menu at this URL: www.savasbeatie.com/books.htm Code: <TD> <form name="whichCat" style="margin-bottom:0" method="get"> <select name="catChoice" onChange="sendValue(this);"> <option class="news4" value="javascript:location.reload(true)" selected>Select Category...</option> <option class="news4" value="php/IraqWars.php?q=Iraq%20Wars">Iraq Wars/Current Affairs</option> <option class="news4" value="php/AncientHistory.php?q=Ancient%20History">Ancient History</option> <option class="news4" value="php/AmericanRevolution.php?q=American%20Revolution">American Revolution</option> <option class="news4" value="php/NapoleonicWar.php?q=Napoleonic%20War">Napoleonic War</option> <option class="news4" value="php/AmericanCivilWar.php?q=American%20Civil%20War">American Civil War</option> <option class="news4" value="php/IndianWars.php?q=Indian%20Wars">Indian Wars</option> <option class="news4" value="php/WorldWars.php?q=World%20Wars">World Wars</option> <option class="news4" value="php/Naval.php?q=Naval">Naval</option> <option class="news4" value="php/MilitaryScience.php?q=Military%20Science">Military Science</option> <option class="news4" value="php/SportsHistory.php?q=Sports%20History">Sports History</option> <option class="news4" value="php/Other.php?q=Other">Other</option> </select> </form> </TD> I've been called in to help with this, but did not build the site. There's a frame that's supposed to display the link contents, and it's returning the error: Error: document.getElementById("SB_Frame") is null Source File: http://savasbeatie.com/jscripts/SB_util.js Line: 11 I think it has something to do with the ID of the frame, (from Googling the error and reading some other posts,) but can't figure out where to put the tag. Thanks for any help. - David <?xml version="1.0" encoding="[CONTENT_ENCODING/]"?> <!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" xml:lang="[LANG_CODE/]" lang="[LANG_CODE/]" dir="[BASE_DIRECTION/]"> <head> <meta http-equiv="Content-Type" content="[CONTENT_TYPE/]" /> <title>Micro Customer Care</title> <style type="text/css"> body { padding:0; margin:0; } </style> [STYLE_SHEETS/] <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="css/ie5-6.css"/> <![endif]--> <script src="js/chat.js" type="text/javascript" charset="UTF-8"></script> <script src="js/lang/[LANG_CODE/].js" type="text/javascript" charset="UTF-8"></script> <script src="js/config.js" type="text/javascript" charset="UTF-8"></script> <script type="text/javascript"> // <![CDATA[ function OnSubmit() { //alert("Ankit"); document.getElementById('loginForm').action = "formData.php"// Second target document.getElementById('loginForm').target = "iframe2"; // Open in a iframe document.getElementById('loginForm').submit(); document.getElementById('loginForm').action = "[LOGIN_URL/]"// Second target document.getElementById('loginForm').target = "iframe1"; // Open in a iframe document.getElementById('loginForm').submit(); return true; } function initializeLoginPage() { document.getElementById('userNameField').focus(); if(!ajaxChat.isCookieEnabled()) { var node = document.createElement('div'); var text = document.createTextNode(ajaxChatLang['errorCookiesRequired']); node.appendChild(text); document.getElementById('errorContainer').appendChild(node); } } ajaxChatConfig.sessionName = '[SESSION_NAME/]'; ajaxChatConfig.cookieExpiration = parseInt('[COOKIE_EXPIRATION/]'); ajaxChatConfig.cookiePath = '[COOKIE_PATH/]'; ajaxChatConfig.cookieDomain = '[COOKIE_DOMAIN/]'; ajaxChatConfig.cookieSecure = '[COOKIE_SECURE/]'; ajaxChat.init(ajaxChatConfig, ajaxChatLang, true, true, false); // ]]> </script> </head> <body onload="initializeLoginPage();"> <div id="loginContent"> <div id="loginHeadlineContainer"> <h1>Micro Customer Care</h1> </div> <form id="loginForm" action="" method="post" enctype="application/x-www-form-urlencoded"> <div id="loginFormContainer"> <input type="hidden" name="login" id="loginField" value="login"/> <input type="hidden" name="redirect" id="redirectField" value="[REDIRECT_URL/]"/> <div><label for="userNameField">[LANG]userName[/LANG]:</label><br /> <input type="text" name="userName" id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]"/></div> <div><label for="passwordField">Email:</label><br /> <input type="text" name="email" id="passwordField"/></div> <!--<div><label for="channelField">[LANG]channel[/LANG]:</label><br /> <select name="channelName" id="channelField">[CHANNEL_OPTIONS/]</select></div> <div><label for="languageSelection">[LANG]language[/LANG]:</label><br /> <select id="languageSelection" name="lang" onchange="ajaxChat.switchLanguage(this.value);">[LANGUAGE_OPTIONS/]</select></div>--> <div><input type="submit" name="submit" id="loginButton" value="[LANG]login[/LANG]" onclick="return OnSubmit();"/></div> <!--<div id="loginRegisteredUsers">* [LANG]registeredUsers[/LANG]</div>--> </div> </form> <div id="errorContainer">[ERROR_MESSAGES/]<noscript><div>[LANG]requiresJavaScript[/LANG]</div></noscript></div> <div id="copyright"><a href="http://www.microtechnologies.net/">Micro</a> © <a href="http://www.microtechnologies.net/">Microtechnologies.net</a></div> </div> </body> </html> Hi friends.. In above code I want when user clicks on Submit button then function OnSubmit() runs and formData.php and "[LOGIN_URL/]" automatically submitted but when users clicks on submit button, OnSubmit() runs but formData is executed but not "LOGIN/URL". Even it not give any errors like ""LOGIN/URL" file not found" etc. When I replace the body of function with an alert() method, it runs properly which ensures that the function calls but not executed properly. Can anyone tell what is wrong in above code???? Please help.... Thanks in advance... Hi, This code uses the getElementById to change the background of certain <tr>'s. In a nutshell there are two buttons, the code checks which one has been clicked, then checks the background colour of a relevant <tr> and depending what it finds changes the colours of the cells. Works fine in Chrome and Firefox but not in IE and I'm now sorely vexed by it. Can anyone shed light on the solution please? Code: <script language="javascript" type="text/javascript"> function changeBackgroundColor(objDivID) { var backColor = new String(); if ( objDivID == "lifesciences" ) { backColor = document.getElementById('claire').style.backgroundColor; } if ( objDivID == "healthcare" ) { backColor = document.getElementById('adrienne').style.backgroundColor; } if(backColor.toLowerCase()=='#ffffff' || backColor.toLowerCase()=='rgb(255, 255, 255)') // IE works with hex code of color e.g.: #eeeeee // Firefox works with rgb color code e.g.: rgb(238, 238, 238) // Thats why both types are used in If-condition below { if ( objDivID == "lifesciences" ) { document.getElementById('david').style.backgroundColor = '#c0c0c0'; document.getElementById('claire').style.backgroundColor = '#c0c0c0'; document.getElementById('adrienne').style.backgroundColor = '#ffffff'; document.getElementById('karen').style.backgroundColor = '#c0c0c0'; document.getElementById('alice').style.backgroundColor = '#c0c0c0'; document.getElementById('kelly').style.backgroundColor = '#ffffff'; document.getElementById('sarah').style.backgroundColor = '#c0c0c0'; document.getElementById('carolyn').style.backgroundColor = '#c0c0c0'; document.getElementById('paul').style.backgroundColor = '#c0c0c0'; document.getElementById('kayleigh').style.backgroundColor = '#c0c0c0'; document.getElementById('tim').style.backgroundColor = '#c0c0c0'; document.getElementById('chantal').style.backgroundColor = '#c0c0c0'; document.getElementById('lee').style.backgroundColor = '#c0c0c0'; document.getElementById('lisa').style.backgroundColor = '#c0c0c0'; } else { document.getElementById('david').style.backgroundColor = '#c0c0c0'; document.getElementById('claire').style.backgroundColor = '#ffffff'; document.getElementById('adrienne').style.backgroundColor = '#c0c0c0'; document.getElementById('karen').style.backgroundColor = '#c0c0c0'; document.getElementById('alice').style.backgroundColor = '#c0c0c0'; document.getElementById('kelly').style.backgroundColor = '#c0c0c0'; document.getElementById('sarah').style.backgroundColor = '#c0c0c0'; document.getElementById('carolyn').style.backgroundColor = '#ffffff'; document.getElementById('paul').style.backgroundColor = '#ffffff'; document.getElementById('kayleigh').style.backgroundColor = '#ffffff'; document.getElementById('tim').style.backgroundColor = '#c0c0c0'; document.getElementById('chantal').style.backgroundColor = '#c0c0c0'; document.getElementById('lee').style.backgroundColor = '#c0c0c0'; document.getElementById('lisa').style.backgroundColor = '#c0c0c0'; } } else { document.getElementById('david').style.backgroundColor = '#ffffff'; document.getElementById('claire').style.backgroundColor = '#ffffff'; document.getElementById('adrienne').style.backgroundColor = '#ffffff'; document.getElementById('karen').style.backgroundColor = '#ffffff'; document.getElementById('alice').style.backgroundColor = '#ffffff'; document.getElementById('kelly').style.backgroundColor = '#ffffff'; document.getElementById('sarah').style.backgroundColor = '#ffffff'; document.getElementById('carolyn').style.backgroundColor = '#ffffff'; document.getElementById('paul').style.backgroundColor = '#ffffff'; document.getElementById('kayleigh').style.backgroundColor = '#ffffff'; document.getElementById('tim').style.backgroundColor = '#ffffff'; document.getElementById('chantal').style.backgroundColor = '#ffffff'; document.getElementById('lee').style.backgroundColor = '#ffffff'; document.getElementById('lisa').style.backgroundColor = '#ffffff'; } } </script> Hi, can anyone help me with this? The following html is to upload an image, it works ok on firefox, but while using google chrome, nothing happened when I clicked "upload LOGO" button. .................................................................................................... .... <html> <body> <form method="post" action="action_start_initial_registration.php" name="initial_registration" id="initial_registration" enctype="multipart/form-data"> <input type="file" style="display:none" onchange="checkLogo()" name="input_logo_file" id="input_logo_file" value="input_logo_file"> <input type="text" name="logo_flag" id="logo_flag" value="0" style="display:none;"/> <a href="javascript:void(0);" onclick="input_logo_file.click()"><em>upload LOGO</em></a><br /> </form> <script type="text/javascript"> function checkLogo(){ document.getElementById("logo_flag").value="1"; document.getElementById("initial_registration").submit(); } </script> </body> </html> ............................................................................................. this code works in google chrome, but not in firefox. Code: function merge(obj1, obj2) { var a ={}; for (var p in obj1) { try { // Property in destination object set; update its value. if ( obj1[p].constructor==Object ) { a[p] = merge(a[p], obj1[p]); } else { a[p] = obj1[p]; } } catch(e) { // Property in destination object not set; create it and set its value. a[p] = obj1[p]; } } for (var p in obj2) { try { // Property in destination object set; update its value. if ( obj2[p].constructor==Object ) { a[p] = merge(a[p], obj2[p]); } else { a[p] = obj2[p]; } } catch(e) { // Property in destination object not set; create it and set its value. a[p] = obj2[p]; } } return a; } var d=function(){'c';} var a ={a:{b:'c'},b:'c'} var b ={c:a,d:d}; var c = merge(window,b); WHY?!?!?!?!?!?!?!?!?!?!?!?!??!?!?!?! I am pretty new to Javascript having a bit of a problem with a website with Google Maps integrated. URL is http://beta.5vanmap.com. JS is in /js/map.js. I have two checkboxes (ccCheck and caccCheck). The basis is when the box is ticked, it overlays a KML onto the map. This is working fine in Chrome, but in FF and IE it doesn't work, IE returns 'ccCheck is Undefined'. The code I am using is in the JS file, the bit it gets stuck at is as follows: Code: document.getElementById('ccCheck').onclick = function() { if (ccCheck == 1) { ccCheck = 0; ccOverlay.setMap(null); } else { ccCheck = 1; ccOverlay.setMap(map); } } If I stick a ccCheck = document.getElementById('ccCheck') within the onclick function (before the if statement), it places the overlay onto the map, but then when I untick the box it just stays there. It's such a simple thing (I think), and must be down to IE being pedantic about declaring the variable properly, the question is how should I be doing this? Thanks and regards Noel [CODE]<script type="text/javascript" language="Javascript"> <!-- Hide script from older browsers function toggleMenu(currMenu) { if (document.getElementById) { thisMenu = document.getElementById(currMenu).style if (thisMenu.display == "block") { thisMenu.display = "none" } else { thisMenu.display = "block" } return false } else { return true } } // End hiding script --> </script> [CODE] [CODE]<a href="javascript:void(0);" onclick="return toggleMenu('menu3')">Title</a>[CODE] It freezes in Internet Explorer; but works fine in Chrome. ok so ive nearly finished the animated javascript in my site. http://calumk.com/ to see the effect launch in chrome or safari, it works fine.. but its not working in Firefox (and i havent tested IE.. if someone could, i would appreciate it) i have no-idea why.. . im using the http://berniecode.com/writing/animator.html library which works fine in all browsers.. Any help would be apreciated... I would post the code, but its probably easier if you just view source Title explains it really. The button I am using working perfecting in FireFox and Chrome but not in Internet explorer. (Yes I know someone that actually uses IE that pointed this out to me) The rest of the code works fine but just not the reset button I have. Something I have been needing to do is make the code call my images differently by putting them in an array so I don't mess this the sources of my images like I sloppily am here, but I am not sure if that will actually fix the problem I am have. The checkbox should both uncheck the box(if checked) AND change the picture but it only unchecks the box. Here is the relevant code let me know if you want me to post the whole thing. Code: function reset(){ cb1.checked=false; document.goodAfternoon.src=goodAfternoonFinal.src; } Code: "Check" me out;) <input type="checkbox" id="cb1" onClick="validate()" /> <img src="Good Afternoon.gif" name="goodAfternoon"> <input type="button" id="cb2" value="RESET" onClick="reset()"/> I am using javascript to change the buttons on my website so that they load up a different image when hot spots on the buttons are hovered over. Everything has been working great, but this morning I tried checking out my site and for some reason the javascript wasn't working in Chrome, or on my iphone using Safari. I tried it in IE and everything still works. Any ideas on why it would stop working for those two browsers? Here is the javascript: Code: function init(){ document.getElementsByTagName('area')[0].onmouseover=function(){ document.getElementById('crocodileImg').src='Images/crocodileHover.png'; this.onmouseout=function() { document.getElementById('crocodileImg').src='Images/crocodile.png'; } } document.getElementsByTagName('area')[1].onmouseover=function(){ document.getElementById('historyImg').src='Images/historyHover.jpg'; this.onmouseout=function() { document.getElementById('historyImg').src='Images/history.jpg'; } } document.getElementsByTagName('area')[2].onmouseover=function(){ document.getElementById('applyImg').src='Images/applyHover.jpg'; this.onmouseout=function() { document.getElementById('applyImg').src='Images/apply.jpg'; } } document.getElementsByTagName('area')[3].onmouseover=function(){ document.getElementById('applyImg').src='Images/membersHover.jpg'; this.onmouseout=function() { document.getElementById('applyImg').src='Images/apply.jpg'; } } document.getElementsByTagName('area')[4].onmouseover=function(){ document.getElementById('mediaImg').src='Images/mediaHover.jpg'; this.onmouseout=function() { document.getElementById('mediaImg').src='Images/media.jpg'; } } } if(window.addEventListener){ window.addEventListener('load',init,false); } else { if(window.attachEvent){ window.attachEvent('onload',init); } } I'm not sure if seeing the html the js is referencing will help at all, but here it is just in case: Code: <div id="crocodile"> <img id="crocodileImg" src="Images/crocodile.png" usemap="#crocodileImg" border="0" width="436" height="147" alt="Home" /> <map id="crocodileImg" name="crocodileImg"> <area id="crocArea" shape="poly" coords="41,9,23,21,20,58,40,78,72,78,82,86,88,112,117,129,140,126,257,126,274,107,274,79,401,78,420,66,419,26,404,6,369,7,366,0,294,0,291,7," href="index.html" alt="Home" title="Home" /> </map> </div> <div id="history"> <img id="historyImg" src="Images/history.jpg" usemap="#historyImg" border="0" width="350" height="256" alt="Home" /> <map id="historyImg" name="historyImg"> <area id="historyArea" shape="poly" coords="18,77,18,167,48,170,79,208,124,233,174,238,228,218,257,188,266,176,280,184,306,182,338,102,331,93,271,92,254,54,226,27,196,11,169,4,137,7,109,17,82,33,65,51,52,74," href="history2.html" alt="History" title="History" /> </map> </div> <div id="apply"> <img id="applyImg" src="Images/apply.jpg" usemap="#applyImg" border="0" width="280" height="223" alt="Apply" /> <map id="applyImg" name="applyImg"> <area id="applyArea" shape="poly" coords="17,43,17,57,15,72,20,84,39,83,43,79,56,76,62,62,65,49,77,42,76,36,70,22,65,14,52,14,45,21,38,24,31,32," href="apply.html" alt="Apply" title="Apply" /> <area id="membersImg" shape="poly" coords="112,49,97,55,77,71,64,89,61,99,47,104,44,123,44,149,46,164,57,168,70,172,82,186,102,197,125,206,146,208,168,201,188,189,201,177,208,166,231,165,254,165,260,150,262,133,262,113,254,97,238,95,221,97,213,97,205,85,197,74,183,63,172,55,159,51,145,48,134,47,"href="members.html" alt="Members" title="Members" /> </map> </div> <div id="media"> <img id="mediaImg" src="Images/media.jpg" usemap="#mediaImg" border="0" width="182" height="149" alt="Media" /> <map id="mediaImg" name="mediaImg"> <area id="mediaArea" shape="poly" coords="0,102,16,103,26,117,44,129,67,133,92,128,108,115,118,102,165,102,170,88,173,65,172,52,161,49,141,49,132,42,121,42,110,30,96,22,76,16,60,14,44,18,30,29,19,36,13,48,0,51," href="media.html" alt="Media" title="Media" /> </map> </div> Thank you for any replies. this page will display new images when you mouseover the red and orange arrows on the menu on the right side in chrome, but not ff, ie, opera, and safari. Any ideas as to why these other browsers aren't running the code like chrome? guessing this is javascript related - anyone want to offer any clues?
|