JavaScript - Javascript Question Regarding Css & Span Classes
Hey all, my first post here. I'm primarily a designer but need to get more into the code aspect of things (and will be getting jQuery asap), but at the moment i'm very behind on time on a project and could use some quick help.
Basically, I'm making a dynamically loading text box input area for RMA returns for our products. But thats kind of irrelevant, here's my question: I have an external style sheet with only this in it (more will be added later for future sections, thats why im making it it's own "css-forms.css" file: Code: .formpad { padding:3px 3px 3px 3px; } In my main .html, some of my javascript for my dynamic table contains lines like these: Code: var esnImeiInput = "<INPUT type=\"text\" name=\"esn_imei[]\" size=\"20\">"; var invoiceInput = "<INPUT type=\"text\" name=\"invoice[]\" size=\"8\">"; var datePurchaseInput = "<INPUT type=\"text\" name=\"date_purchase[]\" size=\"8\">"; var noteInput = "<INPUT type=\"text\" name=\"notes[]\" size=\"18\">"; var trOpenTag = "<tr>"; var trCloseTag = "</tr>"; var tbOpenTag = "<table>"; var formRows = modelInput + reasonInput + esnImeiInput + invoiceInput + datePurchaseInput + noteInput + "<br />"; for(x=0;x<10;x++) { formRows += modelInput + reasonInput + esnImeiInput + invoiceInput + datePurchaseInput + noteInput + "<br />"; } Where inside those vars (INPUT's) would i REFER to the 'class' of .formpad? Basically I just want to add cellpadding to the table that is being dynamically loaded. If anyone has time to help via IM that'd be cool too, this is pretty easy stuff for true coders. (the test page for all of this is currently at: http://planetcellinc.com/rma-rev726.html Any help appreciated, thanks! -Hrl2k Similar TutorialsI'm trying to create a forum for a business. The forum will change depending on what checkbox a person checks in the beginning. I have the checkboxes toggle a certain span. When you check one box it hides one span and displays the other. This works, but I want to position the displayed span at the top so a person doesn't have to look for the other forum. Right now there is just a big white space in the place of the hidden span, so it looks like there is nothing else on the page. I want to move the bottom span to the top when toggled. Here is my code so far. <form name="form1" method="post" action=""> Pork <INPUT TYPE=checkbox NAME="chbx" onClick="selecionatudo(true,1); toggleT('divt1','h'); toggleT('divt2','s')"> Beef <INPUT TYPE=checkbox NAME="chbx" onClick="selecionatudo(true,2); toggleT('divt1','s'); toggleT('divt2','h')"><br> </FORM> <form> <p><div id="divt1" style="visibility:visible; position:relative; top:0; left:0; overflow: visible;"> Shoulder: <br /> Ground beef:<input type="checkbox" name="Grinding" id="Ground beef" /><br /> Patties: Fresh<input type="checkbox" name="pattiesfr" id="Pattiesfr" /> or Seasoned<input type="checkbox" name="pattiesS" id="PattiesS" /><br /> Minute Steaks: <input type="checkbox" name="minsteaks" id="minsteaks" /><br /> Specific Cuts wanted:<br /> <textarea name="Order Sheet" cols="60" rows="30" id="Order Sheet"></textarea> </div> </form><br /> <div id="divt2" style="visibility:visible; position:absolute; top "> Type 2 Input: <input name="t2" type="text" value=""> </div> <BR> </p> <script type=text/javascript> var isIE=document.all?true:false; var isDOM=document.getElementById?true:false; var isNS4=document.layers?true:false; /* _w : which ID (1) or (2) */ /* _h : (h)ide or (s)how */ function toggleT(_w,_h) { if (isDOM) { if (_h=='s') document.getElementById(_w).style.visibility='visible'; if (_h=='h') document.getElementById(_w).style.visibility='hidden'; } else if (isIE) { if (_h=='s') eval("document.all."+_w+".style.visibility='visible';"); if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';"); } else if(isNS4) { if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';"); if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';"); } } </script> I'm integrating a JavaScript typing tutorial to my website. But I'm not able to store the value to the database. In the below code you can see the speed is updated in a html span. The id of the tag is speed(<span id="speed"></span>). This code will automatically update when user start typing. I want to update this to a database when user press submit button. But i cant able to. Is there any way to input the speed to database ? Please go through the below code and suggest me what i can do....? Code: <script type="text/javascript"> //<![CDATA[ var garray = new Array(); var garrayIndex = -1; var gtext = ""; var gindex = 0; var goldPressed = 0; //previous pressed key code var goldTarget = 0; //previous target key code var gtarget = 0; var gpressed = 0; var ggood = 0; var gtotal = 0; var gtime = 0; var gkeytime = 0; function setup() { setEvents(); //change this array to suit your needs but note that indices //must ascend by 1 from 0: garray[0]="foo"; garray[1]="bar";... garray[0] = "a s d f s d f f s d as sd ad fs ds sad af sa fa dafa sda dad das afa sfd add sasd df sf saf dds fd ads safd fsd fas sas dafs as fad"; //more similar lines can easily be added above, dont forget to get the index right! garrayIndex = -1; next(); } function setPatternInit() { //#b note: once we did this using innerHTML but this caused //a leakage of handles in ie var pat = document.getElementById("pattern"); for(; { if (pat.hasChildNodes()) { pat.removeChild(pat.lastChild); } else break; } var cname = "done"; for (j=0; j<gtext.length; j++) { var ch = gtext.charAt(j); if (j>gindex) cname = "future"; else if (j==gindex) cname = "todo"; var kid = document.createElement("span"); kid.className = cname; var txt = document.createTextNode(ch); kid.appendChild(txt); //#b innertext doesnt work on firefox pat.appendChild(kid); } } function setPattern() { var pat = document.getElementById("pattern"); var kids = pat.childNodes; var cname = "done"; for (j=0; j<gtext.length; j++) { if (j>gindex) cname = "future"; else if (j==gindex) cname = "todo"; var kid = kids[j]; kid.className = cname; } } function mapToBoard(code) { if ((code>=97)&&(code<=108)) return (code-32); if ((code>=110)&&(code<=122)) return (code-32); if ((code>=65)&&(code<=90)) return code; if ((code>=48)&&(code<=57)) return code; if ((code==32)) return code; if ((code==44)||(code==46)||(code==47)||(code==59)) return code; return 0; //not on our board picture } function setBoard() { var letter; var elt; var c; var s; if (goldTarget!=0) { c = mapToBoard(goldTarget); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "silent"; elt.className = s; } } if (goldPressed!=0) { c = mapToBoard(goldPressed); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "silent"; elt.className = s; } } if (gtarget!=0) { c = mapToBoard(gtarget); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "target"; elt.className = s; } } if (gpressed!=0) { c = mapToBoard(gpressed); if (c!=0) { letter = "code"+c; elt = document.getElementById(letter); s = "pressed"; elt.className = s; } } } function nextPattern() { goldTarget = gtarget; goldPressed = gpressed; if (++garrayIndex == garray.length) garrayIndex = 0; gtext = garray[0]; gindex = 0; gpressed = 0; setPrompt(); } function prevPattern() { goldTarget = gtarget; goldPressed = gpressed; if (--garrayIndex < 0) garrayIndex = garray.length - 1; gtext = garray[garrayIndex]; gindex = 0; gpressed = 0; setPrompt(); } function next() { nextPattern(); setPatternInit(); setBoard(); } function prev() { prevPattern(); setPatternInit(); setBoard(); } function skip(e) { next(); return false; } function back(e) { prev(); return false; } function setEcho(c, isOK) { var s; if (c<' ') c=' '; var s = "["+c+"]"; if (!isOK) s += " ..OOPS!" var elt = document.getElementById("echo"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function setPrompt() { var ch = gtext.charAt(gindex); gtarget = ch.charCodeAt(0); } function adjustStatistics(ch) { return; //could count errors by character } function updateSpeed(ok) { var t = (new Date()).getTime(); var dt = (t-gtime); gtime = t; if (dt > 5000) return; //ignore sleepy user gkeytime += dt; var s = (0.5+ggood*60*200/gkeytime).toFixed(0) + ""; var elt = document.getElementById("speed"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function updateScore(ok) { if (ok) ggood++; gtotal++; updateSpeed(ok) var s = ggood.toFixed(0) + ""; var elt = document.getElementById("count"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); s = (gtotal-ggood).toFixed(0) + ""; elt = document.getElementById("accuracy"); txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); var s = (gkeytime/1000).toFixed(2) + " s"; var elt = document.getElementById("time"); var txt = document.createTextNode(s); //#b if (elt.hasChildNodes()) { elt.replaceChild(txt, elt.lastChild); } else elt.appendChild(txt); } function reset(e) { window.location.reload(); } function debug() { //#b to use, set body onLoad="debug()" instead of "setup()" in html //document.onkeydown=debugKey; //#b document.onkeypress=debugKey; } function debugKey(evt) { //#b var e = (window.event) ? window.event : evt; //#b var k = (e.which)? e.which : e.keyCode; var f = filterKeyCode(k); var s = "k="+k+",f="+f; alert(s); return false; } function setEvents() { //#b document.onkeydown=down; //#b document.onkeypress=press; (document.getElementById('skip')).onmousedown=skip; (document.getElementById('back')).onmousedown=back; (document.getElementById('reset')).onmousedown=reset; } function cleanup() { //pointless, really document.onkeydown=null; //#b document.onkeypress=null; (document.getElementById('skip')).onmousedown=null; (document.getElementById('back')).onmousedown=null; (document.getElementById('reset')).onmousedown=null; } function filterKeyCode(code) { //from key down (0 to ignore) //note: user must have num lock set if they want to use keypad numbers if ((code>=65)&&(code<=90)) return code; //alpha if ((code>=48)&&(code<=57)) return code; //numberic if (code==32) return code; //blank if ((code>=96)&&(code<=105)) return code; //number pad digits if ((code==13)||(code==16)) return code; //enter, shift if ((code>=106)&&(code<=111)) return code; //number pad operators if ((code>=186)&&(code<=192)) return code; //punctuation if ((code>=219)&&(code<=222)) return code; //punctuation return 0; } function filterCode(code) { //from key press as ascii char code (0 to ignore) if ((code==13)||(code==16)) return code; //enter and shift are allowed if (code<32) return 0; if (code>=127) return 0; return code; } function capsLockFilter(e, pressed) { //#b many problems making this cross browser! //#b e.modifiers known only on early mozilla (which does not know standard e.shiftkey)? var shifted = e.shiftKey || (e.modifiers && (e.modifiers & Event.SHIFT_MASK)); //#b var locked = (((pressed > 64) && (pressed < 91) && (!shifted)) || ((pressed > 96) && (pressed < 123) && (shifted))); if (locked) alert("caps lock!"); } function down(evt) { //#b var e = (window.event) ? window.event : evt; //#b var rawcode = (e.which)? e.which : e.keyCode; pressed = filterKeyCode(rawcode); if (pressed > 0) return true; if (typeof(e.cancelBubble)!="undefined") e.cancelBubble = true; if (typeof(e.stopPropagation)!="undefined") e.stopPropagation(); return false; //#b nuisance keys - backspace etc on ie (no effect for capslock!!) } function press(evt) { //#b //#b should work in ie, firefox, safari(hopefully), opera(hopefully) var e = (window.event) ? window.event : evt; //#b var pressed = 0; var wc = -1; var kc = -1; var cc = -1; if (typeof(e.keyCode)!="undefined") kc = e.keyCode; //ie if (typeof(e.charCode)!="undefined") cc = e.charCode; //firefox if (typeof(e.which)!="undefined") wc = e.which; //old mozilla if ((kc>=0)&&(cc>=0)) { //firefox pressed = cc; } else if (kc>=0) pressed = kc; //ie else if (wc>=0) pressed = wc; //old mozilla //alert("pressed="+pressed+",kc="+kc+",cc="+cc+",wc="+wc); pressed = filterCode(pressed); if (pressed==0) { if (kc==13) return skip(); //#b firefox else return false; } if (pressed==13) return skip(); //#b ie capsLockFilter(e, pressed); //hmm var c = String.fromCharCode(pressed); //ie from ascii code var ch = gtext.charAt(gindex); var ok = (c==ch); goldPressed = gpressed; gpressed = pressed; goldTarget = gtarget; if (ok) { gindex++; if (gindex==gtext.length) { if (gtotal-ggood <= 5 && 0.5+ggood*60*200/gkeytime >= 20) { alert('Good work! You had fewer than 5 errors and typed faster than 20 WPM! Now try the next exercise!'); setPatternInit(); } else if (gtotal-ggood > 5 && 0.5+ggood*60*200/gkeytime >= 20){ alert('Good speed! You were over 20 WPM but have more than five errors! Slow down a bit for accuracy.') setPatternInit(); } else if (gtotal-ggood <= 5 && 0.5+ggood*60*200/gkeytime < 20){ alert('Good accuracy! You had fewer than 5 errors, now try for 20 WPM.') setPatternInit(); } else alert ('Focus on accuracy first, then go for speed!'); setPatternInit(); } else setPattern(); gpressed = 0; setPrompt(); setEcho(c, true); updateScore(true); } else { setEcho(c, false); updateScore(false); setPattern() } setBoard(); return false; } //</XMLCDATA> </script> This is my HTML Code : Code: <body onload="setup()" onunload="cleanup()"> <div id="container1"> <div id="container3"> <div id="body"> <div id="pattern" class="big"> </div> <div id="prompt" class="prompt"> </div> <div id="board" class="board"> <div id="row0" class="row0"> <span id="code49">1</span> <span id="code50">2</span> <span id="code51">3</span> <span id="code52">4</span> <span id="code53" style="margin-left:-5px;">5</span> <span id="code54">6</span> <span id="code55">7</span> <span id="code56">8</span> <span id="code57">9</span> <span id="code48">0</span> </div> <div id="row1" class="row1"> <span id="code81">Q</span> <span id="code87">W</span> <span id="code69">E</span> <span id="code82" style="font-weight:bold">R</span> <span id="code84">T</span> <span id="code89">Y</span> <span id="code85" style="margin-left: -2px;">U</span> <span id="code73">I</span> <span id="code79">O</span> <span id="code80">P</span> </div> <div id="row2" class="row2"> <span id="code65">A</span> <span id="code83">S</span> <span id="code68">D</span> <span id="code70" style="font-weight:bold;">F</span> <span id="code71" style="margin: 0 0 0 -5px;">G</span> <span id="code72">H</span> <span id="code74" style="font-weight:bold;">J</span> <span id="code75">K</span> <span id="code76">L</span> <span id="code59">;</span> </div> <div id="row3" class="row3"> <span id="code90">Z</span> <span id="code88">X</span> <span id="code67">C</span> <span id="code86" style="font-weight:bold">V</span> <span id="code66">B</span> <span id="code78">N</span> <span id="code77" style="font-weight:bold">M</span> <span id="code44">,</span> <span id="code46">.</span> </div> <div id="row4" class="row4"> <span id="code32">[SPACE]</span> </div> <div id="scores"> <div class="count">Characters: <span id="count"></span> </div> <div class="accuracy">Errors: <span id="accuracy"></span> </div> <div class="speed">WPM: <span id="speed"></span> </div> <div class="time">Time: <span id="time"></span> </div> </div> <div align="center"> <button id="reset" class="button123" name="reset" align="center">Restart Exercise</button> </div> </div> <div id="echo" class="echo" style="display:none;"> [] </div> <div style="display:none;"> <button id="skip" class="button123" name="skip">skip</button> to next line ("enter" key is shortcut) </div> <div style="display:none;"> <button id="back" class="button123" name="back">back</button> to previous line </div> </div> </div> Hello, I have looked through a tutorial that does text gradient without the use of images. I found this tutorial: http://www.thomasfrank.se/text_color_gradients.html However, only the first "SPAN CLASS" gets gradiented and the other spans don't. In the bottom of the page it says: Quote: If you call the gradientText.set() without any arguments it will go looking for all span tags with class names starting with gradient_ and apply gradients to them But I do not know what it means, I have tried learning a bit of Javascript and I think it could mean something like "if something is something, then". But I'm not sure. Please help, thanks. Hi all, I have multiple forms on one page with the same element name and one of them is the <span>. Below is my sample code for a simple html file for testing purposes. I have no problem accessing the <input> element, but i had problems with the <span> element. Anyone knows why? In this scenario, i won't be able to use the document.getElementById() as both <span> have the same name. Code: <html> <head> Test <SCRIPT LANGUAGE="JavaScript"> // JavaScript statements go here function test(tmpForm) { window.alert(tmpFrm.elements["weight"].value); window.alert(tmpForm.elements["error"].innerHTML); } </SCRIPT> </head> <body> <form id="form_137" name="form_137"> <input id="weight" name="weight" value="" /> <span id="error" name="error">abc</span> <INPUT TYPE="button" id="btnSubmit" NAME="btnSubmit" VALUE="Submit" onClick="test(this.form);"> </form> <form id="form_137_down" name="form_137_down"> <input id="weight" name="weight" value="" /> <span id="error" name="error">zzz</span> <INPUT TYPE="button" id="btnSubmit" NAME="btnSubmit" VALUE="Submit" onClick="test(this.form);"> </form> </body> </html> Hey all, I am reading a book called JavaScript patterns. In it, this method is created: Code: var klass = function(Parent,template){ var Child, F, i; Child = function () { if (Child.uber && Child.uber.hasOwnProperty("__construct")) { Child.uber.__construct.apply(this, arguments); } if (Child.prototype.hasOwnProperty("__construct")) { Child.prototype.__construct.apply(this, arguments); } } Parent = Parent || Object; F = function () {}; F.prototype = Parent.prototype; Child.prototype = new F(); Child.uber = Parent.prototype; Child.prototype.constructor = Child; for (i in template) { if (template.hasOwnProperty(i)) { Child.prototype[i] = template[i]; } } return Child; } Does anyone have an understanding of why we instantiate a new F() to the Child prototype rather than instantiate the Parent prototype? As you can see above, we assign Parent prototype to F prototype and then instantiate F() object to Child prototype. I'm not sure why it's being done this way. Code: F.prototype = Parent.prototype; Child.prototype = new F(); Thanks for response. Hi Guys, What is the best way to create a javascript class that has all its methods and properties private unless I want them to be public? Many thanks for any help, S Hi everyone, First of all sorry for my english (it is not my native tongue so I don't master it really well) I'm starting a form and I would like to add : <span class="true"></span> where it's written HERE in the following if the function checkField finds that the checking is ok : <div><input type="text" value="" placeholder="Nom" name="nom" class="text" onkeyup="checkField()">HERE<div> I'm a beginner in javascript and in spite of my search I still don't know what to use in my checkField after my test to print <span class="true"></span> where I want it. I would really appreciate any help you guys can give me. Thanks a lot. Is there a way to call javascript functions based on the text between a span element? In other words if I have <span id="mySpan">Bronze</span> then it will call a javascript function but if I have <span id="mySpan">Silver</span> then it will call a different function? Thanks! If the value is negative it should be in red, otherwise it should be in green. It looks like JavaScript completely ignores the css class. Help please. Code: <html> <head> <title>Prva</title> <style type="text/css"> span.Pozitivno { color:green; font-weight:bold; } span.Negativno { color:red; font-weight:bold; } </style> <script type="text/javascript"> function vpisi_stevila() { var a; var b; //Vnos spremenljivk a=prompt("Vnesi stevilo a:") b=prompt("Vnesi stevilo b:") a=a*1 //S tem spremenimo string v int b=b*1 //Izpis stevil if(a<0) { document.write("A:<span class='Negativno'> " + a + " </span> <br />"); } else { document.write("A:<span class='Pozitivno'> " + a + " </span> <br />"); } if(b<0) { document.write("A:<span class='Negativno'> " + a + " </span> <br />"); } else { document.write("A:<span class='Pozitivno'> " + a + " </span> <br />"); } document.write("Vsota:", a+b, "<br />"); document.write("Razlika:", a-b, "<br />"); document.write("Mnozenje:", a*b, "<br />"); document.write("Deljenje:", a/b, "<br />"); document.write("Ostanek:", a%b, "<br />"); if(a>b) //Ce je A vecje od B { document.writeln("A je <b>večje </b> od b") } if(a<b) //Ce je B vecje od A { document.writeln("A je <b>manjse </b> od b") } if(a==b) //Ce sta enaka { document.writeln("A je <b>enako </b> b") } } </script> </head> <body onload="vpisi_stevila()"> </body> </html> Why fail? --> <span onclick="document.bgColor = 'grey';">Grey</span> <span onclick="document.bgColor = 'grey';">Grey</span> does not change the page grey on this page: u s e r s (dot) r c n (dot) c o m / r o b e r t (dot) a c k e r t / g r e y . h t m any ideas why? I think something is blocking it. I think this is a pretty easy to fix error made by a newb ( me. Can anyone tell me why the call to "this.slideNext() " in the code below does not work. Apparently "this.slideNext() " is not a function? Code: function ScoopAnimation(_path, _start, _end, _delay){ this.start = _start this.end = _end; this.delay = _delay; this.path = _path this.currentFrame = _start; this.slideNext() = function (){ this.currentFrame ++; console.log(' next this.currentFrame : ' +this.currentFrame ); } this.start= function () { console.log('next this.start() : ' +this.currentFrame ); //THE NEXT LINE CAUSES THE ERROR! this.slideNext() } this.start(); } I'm trying to figure out this question that was assigned to me, as I haven't done alot on javascript before but I've tried to get most of this, I'm just not sure if this is correct. If anybody could help it would be greatly appreciated. The question is as follows: You are provided with a string array called country that contains the name of every country that the Ski Club visits. For example one element of this array might be as follows: country[0] = "Austria" Another array called villages contains strings with information on village names and altitude in a particular country. For example: villages[0] = "Austria:Seefield 850m*"; Write a JavaScript function snowReport(countryIndex) that will use the arrays provided to write a report of all villages that include a given country. The function will be passed an integer representing the index of an element of the country array. A match is found if the country appears in a string (Hint use appropriate JavaScript function to evaluate if a country name is contained in a village string.) All matching villages should be displayed. Output should be displayed in the villages div element you defined in part (a). Output is shown for a search for Austria in Figure 1b. <script type="text/javascript"> function makeArray() { var country = new Array(5); country[0] = "Austria"; country[1] = "Canada"; country[2] = "France"; country[3] = "Germany"; country[4] = "Switzerland"; return country; var villages = new Array(2); villages[0] = "Austria:Seefield 850m*"; villages[1] = "Austria:Ellam 100m"; return villages; } function snowReport(countryIndex){ var string = ""; for (var i = 0; i < countryIndex.length; i++){ str += countryIndex[i] + " "; } return str; } </script> </head> <body> <script> var x = makeArray(); document.write(snowReport(x)); </script> </body> </html> Many thanks! Hey Guys, I was creating an image map with rollover images. I was just wondering if I could add a fade effect to the transition. The underarms is the only rollover that works at the moment. Please check the source code for the code because it's too long to post here. http://wedezign.com/chris/ So erm. Hello there. I fail at javascript, and yet, I'm trying it. Anyways, I'm working on this thing. It's an extension for google chrome very similar to firefox plugins and so on. I'm making an extension so that, when installed, it changes the look of facebook completely. I have successfully changed the colors. However, I am having some trouble getting my javascript to change images. If anybody out there has some insight on what I'm doing wrong, I am glad to accept any kind of help that anyone is willing to give me, lol. What I've done so far: I have to change the facebook logo (what I'm trying to do now) and then change the links, and very few more things, and I'm done. Problem: I can't figure out how to change the image. I can change the background color, as you saw earlier. I just need a code to change the image. The CSS behind it is: Code: #pageLogo a{background:#3b5998 url(/rsrc.php/z8S5R/hash/ez3x5cuc.png) no-repeat -21px 0;display:block;position:absolute;height:31px;left:-6px;width:103px;top:10px} and the HTML implementing it is: Code: <h1 id="pageLogo"><a href="http://www.facebook.com/?ref=logo" title="Home" accesskey="1"></a></h1> and my structure of javascript is: Code: for(i=0;i<=document.getElementsByTagName("div").length;i++) { if(document.getElementsByTagName("div")[i].id != null) { if((document.getElementsByTagName("div")[i].id=="blueBar")) { document.getElementsByTagName("div")[i].style.backgroundColor='#B22222'; } if(( document.getElementsByTagName("div")[i].id == "headNavOut")) { document.getElementsByTagName("div")[i].style.backgroundColor='#8B0000'; } } } }); I appreciate any help anyone's willing to give. HI Guys!! My name is Megan and I am a college student in need of some JavaScript help for my computer science class!! My professor is making us complete some stupid class project for finals and I can't figure it out! He suggested that we may try to find a JavaScript Website to help us if we have trouble figuring out how to write the code. I have looked and looked and can't find out how to fix my code!! We have to write code to make a slot machine .. I have started the code based on what he gave us and have tried my hardest to figure out how to complete it but I do not know how to finish it. I have the images working correctly (kind of.. the second one seems to have problems loading? I dunno what I did to mess that up) and the counter working, but I need to make it add 13 credits when all 3 images are the same. I added code that I thought would work but it's not for some reason that I can't figure out. It should also pop up an alert screen when all 3 are correct and you win. I guess this would have to be including with the if statement and something like alert('You win 12 credits!!!') Lastly I need to add code that prevents the person from playing when the credit line is 0 (so you can't get - credits!) and I have no idea how to do this. Any help would be greatly appreciated! Here's what I have so far! HI Guys!! My name is Megan and I am a college student in need of some JavaScript help for my computer science class!! My professor is making us complete some stupid class project for finals and I can't figure it out! He suggested that we may try to find a JavaScript Website to help us if we have trouble figuring out how to write the code. I have looked and looked and can't find out how to fix my code!! We have to write code to make a slot machine .. I have started the code based on what he gave us and have tried my hardest to figure out how to complete it but I do not know how to finish it. I have the images working correctly (kind of.. the second one seems to have problems loading? I dunno what I did to mess that up) and the counter working, but I need to make it add 13 credits when all 3 images are the same. I added code that I thought would work but it's not for some reason that I can't figure out. It should also pop up an alert screen when all 3 are correct and you win. I guess this would have to be including with the if statement and something like alert('You win 12 credits!!!') Lastly I need to add code that prevents the person from playing when the credit line is 0 (so you can't get - credits!) and I have no idea how to do this. Any help would be greatly appreciated! Here's what I have so far! Code: <html> <head> <title> Slot Machine</title> <script type="text/javascript" src="http://balance3e.com/random.js"></script> <script type="text/javascript"> function SpinSlots() // Assumes: slot images are in http://balance3e.com/Images // Resultes: displays 3 random slot images { var slot1, slot2, slot3; slot1 = RandomOneOf(['lemon', 'cherry', 'bar']); slot2 = RandomOneOf(['lemon', 'cherry', 'bar']); slot3 = RandomOneOf(['lemon', 'cherry', 'bar']); document.getElementById('slot1Img').src = 'http://balance3e.com/Images/' + slot1 + '.jpg'; document.getElementById('slot2Img').src = 'http://balance3e.com/Images/' + slot2 + '.jgp'; document.getElementById('slot3Img').src = 'http://balance3e.com/Images/' + slot3 + '.jpg'; document.getElementById('credits').innerHTML = parseFloat(document.getElementById('credits').innerHTML) - 1; if (slot1 == slot2 == slot3) { document.getElementById('credits').innerHTML = parseFloat(document.getElementById('credits').innerHTML) + 13; } } </script> </head> <body> <div style="text-align:center"> <p> <img id="slot1Img" border=1 alt="slot image" src="http://balance3e.com/Images/cherry.jpg"> <img id="slot2Img" border=1 alt="slot image" src="http://balance3e.com/Images/lemon.jpg"> <img id="slot3Img" border=1 alt="slot image" src="http://balance3e.com/Images/bar.jpg"> </p> <input type="button" value="Click to Spin" onclick="SpinSlots();"> <p> Credits Remaining: <spin id="credits">20</span> </p> </div> </body> </html> I have an application that has a menu - one of the choices on that menu is "Contacts" - This menu is controlled by css - I've written a script that will modify the css style setting for "display" and "zindex" for the rule that controls the pull down for contacts - this worked for hover, but I am now trying to change to a click event - I successfully change the rule, but the menu doesn't display - not sure if I'm returning incorrectly form the javascript function or what - here's a code snippet: CSS: Code: .primaryNav .subMenu { background-color: #B0967E; position: absolute; width: 300px; left: 600px; /* 823px - 300px - 20 px + 97px */ padding: 10px; display: none; color: #fff; font-size: 90%; } Javascript: Code: <script type="text/javascript"> function SetDisplayCSS() { var mysheet=document.styleSheets[0]; var myrules=mysheet.cssRules? mysheet.cssRules[0].styleSheet.cssRules: mysheet.imports[0].rules; for (i=0; i<myrules.length; i++){ if(myrules[i].selectorText.toLowerCase()==".primarynav .submenu"){ //find "a:hover" rule targetrule=myrules[i]; alert("Rule is found"); break; } } targetrule.style.display = "block"; targetrule.style.zindex = "10"; alert(targetrule.selectorText); alert(targetrule.style.backgroundColor); alert(targetrule.style.position); alert(targetrule.style.width); alert(targetrule.style.left); alert(targetrule.style.padding); alert(targetrule.style.display); alert(targetrule.style.color); alert(targetrule.style.fontSize); alert(targetrule.style.zindex); return true; } </script> html Code (names have been changed to protect the innocent) - note the onclick event handler for the contacts menu option. Code: <li class="pn test"><a href="#" onclick="return SetDisplayCSS();" name="contacts">Contacts</a> <div class="subMenu"> <table width="100%"> <tbody> <col /> <col align="right" valign="top" /> <tr> <td><a href="mailto:abc@xxxxxxx.com">Service Requests</a></td> <td>555.555.5555</td> </tr> <tr> <td><a href="mailto:me@notreal.com">Bugs Bunny</a><br />Tenant Liaison</td> <td>555.555.555</td> </tr> <tr> <td><a href="mailto:blah@blah.com">blah blah</a><br />Client Services Manager</td> <td>123.456.1234</td> </tr> </tbody> </table> <p><a href="xxxxxxxx.htm" class="more">More Contacts...</a></p> </div> </li> Thanks for any help...... I'm not really looking for someone to fix/answer this for me, but maybe give me a hit in the right direction. I need to fix this while loop to run correctly, but has errors in the code. This code is supposed to fill an array with numbers 1 through 100 and then print them. Here is the code: <script type="text/javascript"> /* <![CDATA[ */ var count = 0; var numbers = new Array(100); while (count < 100) { numbers[count] = count; ++count; } while (count < 100 ) { document.write(numbers[count]); ++count; } /* ]]> */ </script> What i am most confused about is this part of the code numbers[count] i don't understand what is going on there. Sorry i am very new to this. Any ideas would be appreciated thank you. I am a newbie with a newbie question =) I recently took an exam type thing using my Firefox browser (v3.5.3). I still have my browser window open that I used, and when I press the back button on the browser I get a message "To display this page, Firefox must send information that will repeat any action ..." Is there any way (either disk or memory cache) to reload the pages with out having to resend the data, OR is there any way (hex editor) to view the exam (forms) questions?? Just curious, Thanks I have a question about Javascript. Hello. I need help with JavaScript enabled. My job so that I can automatically send button to be pushed faster. I use google chrome. For example; Automatically have form filling add-ons. (Autofill), but only to fill the send button will not print. How can I do this automatically? Button codes; <input type='submit' name='post_shout' value='Shout' class='button' /> Google Chrome address bar: javascript: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx what I need to write here? Can I do it after 1-2 seconds and fill out? Many thanks in advance. (My English is poor) |