JavaScript - Combination Script For Game Not Working
I am very new to javascript. At least when it comes to writing scripts. The only thing I'm trying to do with the following script is make it so when you click on the right numbers of the image it will take you to a new page. If you click the wrong numbers it will forward you to an error page explaining that the code/numbers you clicked on were wrong. The code of numbers is four numbers long.
When I try the correct numbers or the incorrect numbers nothing happens either way. I'm not sure why. Code: <html><head><title>Untitled</title> <script type="text/javascript"> var combination; var comboAnswer = "7256"; combination = ""; function keycode(n) { if (combination.length < (opener.top.comboAnswer.length - 1)) { combination = combination + n; } else { combination = combination + n; checkCode(); } } function checkCode() { if (combination == opener.top.comboAnswer) { window.location.href = "disarmed.html"; } else { window.location.href = "armed.html"; } } </script> <body bgcolor="#000000"> <center> <div style="text-align:center; width:527px; margin-left:auto; margin-right:auto;"> <img id="combination" src="image.png" usemap="#combination" border="0" alt="" /> <map id="_combination" name="combination"> <area shape="rect" coords="255,184,288,210" href="javascript:keycode(1)" alt="" title="" /> <area shape="rect" coords="288,184,321,210" href="javascript:keycode(2)" alt="" title="" /> <area shape="rect" coords="321,184,354,210" href="javascript:keycode(3)" alt="" title="" /> <area shape="rect" coords="255,213,288,239" href="javascript:keycode(4)" alt="" title="" /> <area shape="rect" coords="288,213,321,239" href="javascript:keycode(5)" alt="" title="" /> <area shape="rect" coords="320,213,353,239" href="javascript:keycode(6)" alt="" title="" /> <area shape="rect" coords="256,240,289,266" href="javascript:keycode(7)" alt="" title="" /> <area shape="rect" coords="288,240,321,266" href="javascript:keycode(8)" alt="" title="" /> <area shape="rect" coords="320,240,353,266" href="javascript:keycode(9)" alt="" title="" /> <area shape="rect" coords="288,265,321,291" href="javascript:keycode(0)" alt="" title="" /> <area shape="default" nohref> </map> </div> </center> </body></html> Similar TutorialsHi, Well I had lots of scripts so what I did is that I combined all of them into one script file, which contains files like Jquery library too. But now the problem is that it has stopped working, I don't know why did this happen. What I did is that I took every script copied and pasted it and then I gave some space under it by pressing enter a few times and then I used to paste other script, I was told this was the method to combine scripts but now the scripts don't work. Here is the link to combined scripts http://files.cryoffalcon.com/bloghut...NCOMPRESSED.js And the link to a live example is http://bloghutsbeta.blogspot.com/ Hello everyone. I have a tic tac toe game I am working on and I managed to make it so you can place X's and O's respectively. My next problem is making a win condition so it checks to see if the X's won the game or the O's did. Here is what I have so far. Edit fiddle - JSFiddle What I am basically thinking is that when you are clicking I want whatever letter it is that is placed to be saved and then I can check to see if all 3 are equal to that letter. It is a bit hard to explain. Essentially I want to make a win condition. If anyone could throw some assistance my way that would be great. I know for sure it requires a lot of checks because there are so many different ways of winning, I just need to know that initial one. Thank you very much. I need help editing a script used for ease of play on an online game. I received the original script from a friend who no longer plays and who doesn't know how to fix it with the game design having changed. The script string that needs edited is as follows: function unocc_list(arr) { var html= ""; var user_coords = []; user_coords = xy_from_id(_current_planet.substr(0,6)); var data = new Array(); var i =0; while (arr[i]) { var c = arr[i]; var z = c.id; var y = c.system; var link = ""; link += "http://speed.imperion.org/fleetBase/mission/1/planetId/"; link += z; link += "/m/301/ships/,0,25,0,0,0,0,0,0,0,0,0,0"; // XEN, Mylons // link += "/m/301/ships/,0,0,1,0,0,0,0,0,0,0,0,0"; // TITAN, Large Transports // link += "/m/301/ships/,0,4,0,0,0,0,0,0,0,0,0,0"; // TERRAN, Small Transports var this_planet_coords = xy_from_id(c.system); var d = distance_between (user_coords, this_planet_coords); var raw_time = c.lastAttackTime; var tt = raw_time.split("."); var dx = tt[0]+ "."+tt[1]+".20"+tt[2]; var t1 = Date.parse(dx); var now = new Date(); var time_delta = (now - t1) /(60 *60* 1000); time_delta = Math.floor(time_delta); var a =""; switch (true) { case (time_delta < 10): a = "<span style='background: hsl(0,00%,70%); text-align: right;' title='Last attacked over "+time_delta+" hours ago'>"+time_delta+"</span>"; break; case (time_delta >= 10 && time_delta < 100 ): a = "<span style='background: hsl("+time_delta+",70%,70%); text-align: right;' title='Last attacked over "+time_delta+" hours ago'>"+time_delta+"</span>"; break; case (time_delta > 99): a = "<span style='background: hsl(100,70%,70%); text-align: right;' title='Last attacked over "+time_delta+" hours ago'>"+time_delta+"</span>"; break; } var q = c.quality.toFixed(2)+"\t"; if (c.quality > 1) { if (c.quality > 1.15) { q = "<b>"+q+"</b>"; } q = "<span title='"+c.typeName+"'>"+q+"</span>"; } else { q = "<span style='opacity: 0.4;'>"+q+"</span>"; } data[i] = {}; data[i].dist = d; data[i].code = "\n"+q+a+"\t<a href='"+link+"'>"+ z +"</a>\t("+this_planet_coords["x"] + "|" + this_planet_coords["y"]+") \tDistance: "+d; i++; } data.sort(cmp_d); var j = 0; while (data[j]){ html += data[j].code; j++; } open_pop_up (html, "boo", "[*] UnAnnexed/UnOcc Planets"); The code is supposed to pull up a list of all 'planets' in the game(for a certain distance) that are noT currently occupied or annexed by any other players. It however won't even recognize that there are any. I have the full script available if anyone wishes to look at it. As well as source code from the game itself. I'm not sure how much of the source code is even relevant so Instead of posting the four page blah blah blah Anyone who wants to help I can send a saved copy of it to them. Here are a series of screen shots I took to give you an idea of whats going on. Frame 1 Frame 2 Frame 3 Hi, I'm trying to put some kind of code for some kind of facebook game but then the problem that I'm having is this code kinda broken now, which is mean not really support to the new facebook platform or new version of facebook and the facebook game have change many links in itself I try to update it but never success on this project, if someone could assist me where to start or what to do please do so will be much appreciate for the help in advance Code: javascript:( function() { var d, url, t, i; d = window.open().document; url = location.href; d.write('<p>'); if (url.match(/clearance/)) { var user_id; var pets, li, im; var pet_link, pet_id, pet_name, pet_seller, pet_price; t = document.getElementById('app7019261521_my_monies') .getElementsByTagName('a')[0].getAttribute('href'); user_id = t.substr(t.lastIndexOf("/") + 1); d.write(' HotBuys</p>'); d.write('<table><tr><td valign="top"><table>'); pets = document.getElementsByClassName('user-item on_sale'); for (i = 0; i < pets.length; i++) { im = pets[i].getElementsByTagName('img'); if (im.length > 0) { t = im[0].getAttribute('src'); } else { t = "http://static.ak.fbcdn.net/pics/s_silhouette.jpg" } li = pets[i].getElementsByClassName('text')[0].getElementsByTagName('li'); pet_link = li[0].getElementsByTagName('a')[0].getAttribute('href'); pet_id = pet_link.substr(pet_link.lastIndexOf("/") + 1); pet_name = li[0].getElementsByTagName('a')[0].firstChild.nodeValue; pet_price = li[1].getElementsByClassName('money')[0].firstChild.nodeValue; if (i%5 == 0) { d.write('<tr>'); } d.write('<td width="100px" valign="top">'); d.write('<a style="font-size:60%" rel="nofollow" target="P" href="' + pet_link + '">'); d.write('<img width="100" height="100" src="' + t + '"/></a><br/>'); d.write('<a style="font-size:60%" rel="nofollow" target="P" href="' + pet_link + '">' + pet_name + '</a><br/>'); d.write('<span style="font-size:70%">' + pet_price + '</span>'); d.write('<table><tr><td>'); d.write('<form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td><td>'); d.write('<form method="post" rel="nofollow" target="Q" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td></tr></table></td>'); if (i%5 == 4) { d.write('</tr>'); } } d.write('</table></td><td valign="top">'); d.write('<iframe name="P" width="400" height="540"></iframe>'); d.write('<iframe name="Q" width="400" height="540"></iframe>'); d.write('</td></tr></table>'); } else if (url.match(/users\/show/)) { var user_id, pet_id, pet_name, pet_value, pet_cash; var info, info_money, title_icon; var achievements, badges, badge_pages, badge_count, n_tycoon = 0, n_collar = 0; t = document.getElementById('app7019261521_my_monies') .getElementsByTagName('a')[0].getAttribute('href'); user_id = t.substr(t.lastIndexOf("/") + 1); t = url.match(/users\/show\/[0-9]+/)[0]; pet_id = t.substr(t.lastIndexOf("/") + 1); t = document.title; pet_name = t.substr(t.lastIndexOf("|") + 2); info = document.getElementsByClassName("info"); info_money = info[0].getElementsByClassName("money"); pet_value = info_money[0].firstChild.nodeValue; pet_cash = info_money[1].firstChild.nodeValue; title_icon = document.getElementsByClassName("general")[0] .getElementsByClassName("title_icon"); achievements = document.getElementsByClassName("achievements"); if (achievements.length > 0) { } d.write('</span> <span style="color:#777">value:</span> ' + pet_value); d.write(' <span style="color:#777">cash:</span> ' + pet_cash); d.write(' <a href="http://apps.facebook.com/friendsforsale/comments?a=' + user_id + '&b=' + pet_id + '" rel="nofollow" target="P">C2C</a>'); d.write(' <a href="http://apps.facebook.com/friendsforsale/users/admin_dialog/' + pet_id + '" rel="nofollow" target="P">AD</a></p>'); d.write('<table border="0" cellpadding="0" cellspacing="0"><tr>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="Q" action="http://apps.facebook.com/friendsforsale/users/buy/' + pet_id + '">'); d.write('<input name="buyer_id" type="hidden" value="' + user_id + '"/>'); d.write('<input type="submit" value="Buy"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/update/' + pet_id + '">'); d.write('<input name="" type="submit" value="Nick"/><input name="nickname" type="text" size="10"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/sale/' + pet_id + '">'); d.write('<input name="" type="submit" value="Sale"/></form></td>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/release/' + pet_id + '">'); d.write('<input name="" type="submit" value="Free"/></form></td></tr></table>'); d.write('<table border="0" cellpadding="0" cellspacing="0"><tr>'); d.write('<td><form method="post" rel="nofollow" target="P" action="http://apps.facebook.com/friendsforsale/users/' + pet_id + '/comments/create">'); d.write('<input name="" type="submit" value="Comment"/><textarea rows="1" col="20" name="comment" type="text" style="vertical-align:top"></textarea></form></td>'); d.write('</tr></table>'); d.write('<iframe name="P" width="400" height="540"></iframe>'); d.write('<iframe name="Q" width="400" height="540"></iframe>'); } else { d.write(' </p>'); } d.write('</body></html>'); d.close(); } )() Hi Guys, i have two different arrays with the same number of element. The 1st array holds the ID's and the 2nd one holds the Items.. i want to use both of them in a Jquery autocomplete plugin.. showing the the 2nd one values but getting the value of the 1st arr. I was wondering if there is a way to combine both in one in Javascript like Arr3 =[arr1, arr2] where i display arr2 elemnt and pass arr1 elements? thanks Hi All Not sure if this is the right place to post but could do with some help. Scenario: 1 Box holds 3 items, Complete box weighs 75g, each item 25g, customer chooses their own 3 combo items. This could be the same all the same item or 3 different items. I need a script that will require the selections to make up 75g in order to continue the process. i.e customer can only continue when 3 items / 75g worth are selected. Here is a short version, I have about 12 selectors at the moment and possible more will be created (if that matters). Code: <form name="cart_quantity" action="myProduct?action=add_product" method="post" enctype="multipart/form-data"> < <div class="placeholder"> <img src="" alt="Image Placeholder" /> </div> <label class="attribsSelect" for="attrib-6">Hard Boiled 1</label><br /> <select name="id[6]" id="attrib-6"> <option value="">Select Portion</option> <option value="24">25g</option> <option value="25">50g</option> <option value="26">75g</option> </select> <div class="placeholder"> <img src="" alt="Image Placeholder" /> </div> <label class="attribsSelect" for="attrib-7">Hard Boiled 2</label><br /> <select name="id[7]" id="attrib-7"> <option value="">Select Portion</option> <option value="27">25g</option> <option value="28">50g</option> <option value="29">75g</option> </select> <div class="placeholder"> <img src="" alt="Image Placeholder" /> </div> <label class="attribsSelect" for="attrib-8">Hard Boiled 3</label><br /> <select name="id[8]" id="attrib-8"> <option value="">Select Portion</option> <option value="30">25g</option> <option value="31">50g</option> <option value="32">75g</option> </select> <div class="placeholder"> <img src="" alt="Image Placeholder" /> </div> <label class="attribsSelect" for="attrib-9">Hard Boiled 4</label><br /> <select name="id[9]" id="attrib-9"> <option value="">Select Portion</option> <option value="33">25g</option> <option value="34">50g</option> <option value="35">75g</option> </select> </form> The section of the form is just the portion with selctors, there are other fields with radio buttons for color choice etc. I have searched for something like this all over but cant find it. Please please please could some genius out there help. Thanks in advance Ok so i want to work on an EASY basic game. As simple as Guess what number... But there are some twist... Ok So here is my example... (HTML, i know this.)I'm Guessing a number 1-99. What is it? (java) Lets say its 66 and they guess 53, have the text rusult be in a pop up window be: Too low! (java) Lets say they guess 78, have the text rusult be in a pop up window be: Too high! (java) Lets say they guess 100+, have the text rusult be in a pop up window be: Out of range! (java)But lets say they guess 66, have a text result be in a pop up window be: You've won! (java) I want a text field where you can enter your answer, and it will do the actions above. Can anyone code this? Thanks for reading! This is a simple basic game i want to make. Its a "What Am I" Riddle... The questions is (In HTML which i already know): I'm as light as a feather but no man can hold me for long. What am I? the answer is: Your Breath. (This is where the JAVASCRIPT comes in) Lets say they guess a rock, have a pop up say: Wrong Answer. Please try again. Lets say they guess Your breath -OR- Breath, have a pop up say: Correct! I want a text field where you can enter your answer, and if they choose ANYTHING but the 2 correct answers above, it will display please try again. Can anyone code this please? Thanks for reading. We have an ASP website which everything works fine in pre-IE8, firefox and even our iPhone browsers but not IE8. I know what the problem is and where the problem is but don't know how to fix it, it should be pretty simple but I am not a developer...just trying to fix this one problem When the page loads it is supposed to automatically fill in a text box with the word: No This is the javascript that is supposed to do that: Code: <script type="text/javascript"> function statusdefault(oSel) { status = 'No'; document.getElementById('theLabel5').value = status; } </script> and this shows the onload line: Code: <body onload="statusdefault(this)" bgcolor="#FFFFFF" background="images/background_stripe.jpg" text="#000000" link="#CCCCCC" vlink="#CCCCCC" alink="#CCCCCC" leftmargin="0" topmargin="10" marginwidth="0" marginheight="10"> <form action="<%=MM_editAction%>" method="POST" name="frmDetail" id="frmDetail"> additionally when someone changes a selection in one of the comboboxes it should change the textbox to: Yes Here is the code for that (which also does not work): Code: <script type="text/javascript"> function statusupdated(oSel) { status = 'Yes'; document.getElementById('theLabel5').value = status; } </script> which of course gets triggered by this: Code: <select name="lstQueue" id="select" onChange="statusupdated(this)"> This is the code for the said textbox: Code: <input name="txtStatusUpdated" type="text" id="theLabel5" value="<%=(rsQ.Fields.Item("StatusUpdated").Value)%>"> The error I get in IE8 is "This page cannot be displayed..." and give a http500 error with no other info. It looks like this javascript code was copied and pasted throughout this same ASP page and altered to do different things. All of the other scripts like this one work fine so I know it is just something in these particular ones that have a problem. Thanks for any help that can be given!!! Scott Hey, I'm a total noob when it comes to javascript. and manged to make this code for a different forum: Code: //This script was created by TROPAFLIGHT2 var d=new Date(); var theDay=d.getDay(); switch (theDay) { case 1: document.write("<EMBED src="http://bit.ly/Ky9R5F" autostart=true loop=true volume=100 hidden=true>"); break; case 2: document.write("<EMBED src="http://bit.ly/Ky9R5F" autostart=true loop=true volume=100 hidden=true>"); break; case 3: document.write("<EMBED src="http://bit.ly/JGUdU9" autostart=true loop=true volume=100 hidden=true>"); break; case 4: document.write("<EMBED src="http://bit.ly/JMVvl0" autostart=true loop=true volume=100 hidden=true>"); break; case 5: document.write("<EMBED src="http://bit.ly/JVq7yb" autostart=true loop=true volume=100 hidden=true>"); break; case 6: document.write("<EMBED src="http://bit.ly/J7fvwY" autostart=true loop=true volume=100 hidden=true>"); break; default: document.write("<EMBED src="http://bit.ly/J2mc7a" autostart=true loop=true volume=100 hidden=true>"); } That code obviously didn't work so I manged to fix certain things: Code: //This script was created by TROPAFLIGHT2 var d=new Date(); var theDay=d.getDay(); switch (theDay) { case 1: document.write;"(<EMBED src="//bit.ly/Ky9R5F" autostart=true loop=true volume=100 hidden=true>)"; break; case 2: document.write;"(<EMBED src="//bit.ly/Ky9R5F" autostart=true loop=true volume=100 hidden=true>)"; break; case 3: document.write;"(<EMBED src="//bit.ly/JGUdU9" autostart=true loop=true volume=100 hidden=true>)"; break; case 4: document.write;"(<EMBED src="//bit.ly/JMVvl0" autostart=true loop=true volume=100 hidden=true>)"; break; case 5: document.write;"(<EMBED src="//bit.ly/JVq7yb" autostart=true loop=true volume=100 hidden=true>)"; break; case 6: document.write;"(<EMBED src="//bit.ly/J7fvwY" autostart=true loop=true volume=100 hidden=true>)"; break; default: document.write;"(<EMBED src="//bit.ly/J2mc7a" autostart=true loop=true volume=100 hidden=true>)"; } Problem is, it still doesn't work and I don't really know why. I've stared at it for a long time but the problem didn't click like last time. Any help at all would be appreciated. Thanks in advance, me. Ok, I've determined that my problem wasn't in the script itself, but in the fact that Opera 10 Beta 2 apparently does not recognize the "onload" attribute of the body tag. Is there a way to work around this?
Hello, Im new to scripting. I have 2 scripts that work in firefox but not in ie. I was wondering if anyone could help me? The First Javascript Code: <SCRIPT language="javascript"> <!-- // ***** GET TOTAL function CalculateSum(setup, month, plan, form) { var A = parseFloat(setup); var B = parseFloat(month); form.x_amount.value = A + B; form.user5.value = plan; } --> </SCRIPT> The second javascript Code: var os_price = 0; var base_price = 0000; var total_carryover = 0000; function show_price() { features = 0; for(var pr in price) { features+=price[pr]; } month = features + base_price + os_price ; total = month + total_carryover; document.getElementById('setup_price').innerHTML="$"+(setup)/100; document.getElementById('monthly_price').innerHTML="$"+(month)/100; document.getElementById('total_price').innerHTML="$"+((total)/100+setup/100); } Thanks in advance for any help. Hey: I have two javascripts on my page but one isn't showing with both codes in page. [CODE]<script type="text/javascript" src="js/image-slideshow.js"></script>[ICODE] The above code is for the image slide. When this is in the html the other one doesn't work (a text changer). The wbesite is http://www.uwics.com/constitution.htm There is no text at the top of the page currently. If you check Home you'll see how it should be. Any help would be greatly appreciated. Thank you, Mitka Hi there, i have this simple script that replaces the scrollbar of an iframe called iFrame1 with 2 up and down arrow images, but it only works in IE, i've tried it in Chrome and Firefox... here is the code Code: <script type="text/javascript" language="javascript"> function bsh_iFrame1(step,time){hs_iFrame1=setInterval("sh_iFrame1("+step+")",time)} function esh_iFrame1(){clearInterval(hs_iFrame1)} function sh_iFrame1(step) { scrollx=iFrame1.document.body.scrollLeft scrolly=iFrame1.document.body.scrollTop scrolly=scrolly+step iFrame1.window.scroll(scrollx,scrolly) } </script> Code: </td><td align="center" valign="middle" width="31"><img src="up.png" alt="up" border=0 vspace="5" hspace="3" onMouseDown="esh_iFrame1();bsh_iFrame1(-3,2)" onMouseUp="esh_iFrame1();bsh_iFrame1(-1,20)" onMouseOver="bsh_iFrame1(-1,20)" onMouseOut="esh_iFrame1()"><br> <img src="down.png" alt="down" border=0 vspace="5" hspace="3" onMouseDown="esh_iFrame1();bsh_iFrame1(3,2)" onMouseUp="esh_iFrame1();bsh_iFrame1(1,20)" onMouseOver="bsh_iFrame1(1,20)" onMouseOut="esh_iFrame1()"> thanks in advance for any answers... Hi all, thanks in advance for any help. For a lot of years now I've used a javascript that does a simple rollover image swap, but also changes another alternate image at the same time. It's always worked like a charm. Lately I realized that the script no longer works in IE, though it used to in older versions of IE (I think it stopped working in anything past IE 7). It still works fine in Firefox, Safari, etc. I haven't been able to find a good alternative for this script, so I'm really trying to get it to work again in IE, but so far no luck. Here's the link to the actual script itself. http://www.jsmadeeasy.com/javascript...nges/index.htm (you can see that even the example on this page doesn't work in IE anymore) You can also see it in action at this site: http://www.augustroad.com/ (notice when you roll over the menu bar an alternate image appears in FF, but not in IE). Again, thanks in advance for any help. I truly appreciate it! Jordan <script type="text/JavaScript"> function refreshPage(s) { window.location.reload(); if((s.options[s.selectedIndex].value) = "zed=catcher") { alert (s.selectedIndex); //this is showing <?PHP //the next lines does not execute????? echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; ?> } } </script> please help? thanks i have a script that measures the window size and - at this point - only adjusts the width of one css element. first function: Quote: var myWidth = 0, myHeight = 0; function getWindowSize() { if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } // window.alert( 'Width = ' + myWidth ); // window.alert( 'Height = ' + myHeight ); } second function: Quote: //changecss JavaScript Functions by Shawn Olson //Copyright 2006-2008 //http://www.shawnolson.net function changecss(theClass,element,value,sheet) { //Last Updated on October 10, 1020 //documentation for this script at //http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html //ms: 5.5.11 added sheet: you have to point at the stylesheet by number var cssRules; var added = false; var mySheet = document.styleSheets[sheet]; if (mySheet['rules']) { cssRules = 'rules'; } else if (mySheet['cssRules']) { cssRules = 'cssRules'; } else { //no rules found... browser unknown } for (var R = 0; R < mySheet[cssRules].length; R++) { if (mySheet[cssRules][R].selectorText == theClass) { if(mySheet[cssRules][R].style[element]){ mySheet[cssRules][R].style[element] = value; added=true; break; } } } if(!added){ try{ mySheet.insertRule(theClass+' { '+element+': '+value+'; }',mySheet[cssRules].length); } catch(err){ try{mySheet.addRule(theClass,element+': '+value+';');}catch(err){} } } } i call the function in a php script that is to rule out that the server is talking to a mobile device, however, it echos javascript and a document ready function: Quote: $useragent=$_SERVER['HTTP_USER_AGENT']; if(preg_match('/android|...(non relevant code)...|zte\-/i',substr($useragent,0,4))) { echo '<link rel="stylesheet" type="text/css" href="1" />'; //the above never happens as i am testing on big screen } else { //echo '<link id="screensize" rel="stylesheet" type="text/css" href="stylesheet.php?cssid=47&mediatype=screen" />'; echo '<script type="text/javascript">'; echo '$(document).ready(function() { getWindowSize(); //ms: these variables come back: myWidth, myHeight if (myWidth >=1225) { changecss(".core-pageWidth","width","1225px",1); } else if (myWidth >1000) { myWidth=myWidth - 20; changecss(".core-pageWidth","width",myWidth+"px",1); } else if (myWidth >910) { myWidth=myWidth - 20; changecss(".core-pageWidth","width",myWidth+"px",1); } }); </script>'; } the changecss() does not work in https but works fine in http. is this to be expected? mario Hi All, I am using one script which is functioning properly incase of IE but incase of Mozilla evenif the shift key is pressed and any character key is pressed then it is displaying Caps Lock is On. can anyone tell how can I make it Mozilla and IE compatible. Dear All Experts I wrote a simple code in javascript and it is working fine with IE but when I open the page in FireFox or in Google Crome it is not working as I expect. Actually I am enabling and disabling the combo box on the on change event of radio button. Please check the code attached here. And visit my site for output www.crispwerx.com/catasset Thanx to all viewer and helper Nice for a change: a piece of code that does work in all versions of IE, but not in Firefox. I'm stuck. Code: <img alt="Loodgieters" title="Loodgieters" src="/core/loodgieters_uit.png" name="loodgieters" border="0" style="margin-right:1px; margin-top:1px; float:left; cursor:pointer;" onclick="document.location='/pages/loodgieters.php';" onmouseover="foto1.style.backgroundColor='#392d63'; loodgieters.src='/core/loodgieters_aan.png'" onmouseout ="foto1.style.backgroundColor='#008ac9'; loodgieters.src='/core/loodgieters_uit.png'" /> Explanation: element "loodgieters" is a menu button that should change on mouseover. It doesn't in FF, it does in IE. Secondly, when you "mousover" the image, it should change the backgroundcolor of a second element (foto1). Element 'foto1' is a table cell. In return, when you mouse-over this table cell, the image element 'loodgieters' should change as well. So it's a two-way thing. The code for the table cell is: Code: <td height="189" id="foto1" bgcolor="#008ac9" valign="top" onmouseover="style.backgroundColor='#392d63'; loodgieters.src='/core/loodgieters_aan.png';" onmouseout="style.backgroundColor='#008ac9'; loodgieters.src='/core/loodgieters_uit.png';" style="cursor:pointer;" onclick="document.location='/pages/loodgieters.php';"> <img alt="Loodgieters" title="Loodgieters" src="/core/loodgieters.png" style="border:0; margin-left:auto; margin-right:auto; margin-top:10px; display: block;" /></td> Again: it all works as I expected in IE, Safari and Chrome, but it does not in Firefox. The whole page validates as XHTML 1.0 Transitional What am I overlooking here? I'm stuck. Any help is welcome |