JavaScript - Are Functions "first Class Objects?" And Javascript != Javascript
I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara";
Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? Similar TutorialsCould you make a if statment for adding points to Fel,Dom or Blob. <script type="text/javascript"> Blob = 500 Fel = 300 Dom = 400 if (Fel == Dom && Dom == Blob) { document.write("<b>It was a tie!</b>") } else if (Blob == Dom || Dom == Blob) { document.write("<b>Dom and Blob!</b>"); } else if (Fel == Dom || Dom == Fel) { document.write("<b>Dom and Fel!</b>"); } else if (Blob == Fel || Fel == Blob) { document.write("<b>Blob and Fel!</b>"); } if (Fel > Blob || Fel > Dom ) { document.write("<b>Fel!</b>"); } else if (Dom > Fel || Dom > Blob) { document.write("<b>Dom!</b>"); } else if (Blob > Dom || Blob > Fel) { document.write("<b>Blob!</b>"); } </script> Hi all, I've messing around with CSS and I would like to change the <body> 'class' when the user selects a hyperlink. To do this I've employed the OnClick method within the hyperlink which calls the function updateBodyClass(). Within upDateBodyClass() I would like to add the string "extraMenu" to the body class. Before selecting the hyperlink the body is: <body id="twoColLayout" class="tools"> I want this to change to: <body id="twoColLayout" class="tools extraMenu"> This is the code I currently have but it doesn't work. Please can someone point me in the right direction. Thankyou in advance for your time. <html> <head> <title>test</title> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script> function updateBodyClass() { document.getElementById("body").className="tools"; document.getElementById("body").className+=" extraMenu" return; } </script> </head> <body id="twoColLayout" class="tools"> <a href="index.php" onClick="updateBodyClass()">Search Bookmarks</a> </body> </html> Hi guys, I have a JS calculator on my website which is basically a load of radio buttons that the user clicks and as they do so a price is calculated in their view. At the moment - the price box starts with a blank box but is essentially "0". Then, as the user select an option, the price appears and then starts to calculate when more than 1 is pressed. All I want to do is have the price start at "300" instead of a blank box or "0". Then the rest of the options calculate onto that. I have tried a variety of ways to achieve it and seem to be missing something! I am pretty new to JS although do have a basic understanding ..... clearly not enough to do this thou! lol Basically imagine 300 is the initial price. That only gets charged once ... Here's my code .... In the <head> Code: <script type="text/javascript"> function getRBtnName(GrpName) { var sel = document.getElementsByName(GrpName); var fnd = -1; var str = ''; for (var i=0; i<sel.length; i++) { if (sel[i].checked == true) { str = sel[i].value; fnd = i; } } return fnd; // return option index of selection // comment out next line if option index used in line above // return str; } function chkrads(rbGroupName) { var ExPg = [ [0,''], [100,"1 extra page"], [200,"2 extra pages"], [250,"3 extra pages"], [300,"4 extra pages"], [350,"5 extra pages"] ]; var ExEm = [ [0,''], [10,"1 extra email"], [20,"2 extra emails"], [30,"3 extra emails"], [40,"4 extra emails"], [50,"5 extra emails"] ]; var ImgBun = [ [0,''], [10,"3 extra image"], [20,"5 extra images"], [30,"7 extra images"], [40,"10 extra images"] ]; var rbtnGroupNames = ['extrapages','extraemail','imagebundles']; var totalprice = 0; var tmp = ''; var items = []; for (var i=0; i<rbtnGroupNames.length; i++) { tmp = getRBtnName(rbtnGroupNames[i]); if (tmp != -1) { switch (i) { case 0 : totalprice += ExPg[tmp][0]; if (tmp > 0) { items.push(ExPg[tmp][1]); } break; case 1 : totalprice += ExEm[tmp][0]; if (tmp > 0) { items.push(ExEm[tmp][1]); } break; case 2 : totalprice += ImgBun[tmp][0]; if (tmp > 0) { items.push(ImgBun[tmp][1]); } break; } } } document.getElementById('QUOTED_PRICE').value = totalprice; document.getElementById('ITEMS_SELECTED').value = items.join('\n'); document.getElementById('PRICE_IN_VIEW').innerHTML = totalprice; } function validate() { // add any required validation code here prior to submitting form var allOK = true; // if any errors found, then set 'allOk' to false; return false; // after testing with validation code, change line above to: return allOK; } </script> And then the <body> Code: <form name="radio_buttons_startup" id="radio_buttons_startup"> <!--EXTRA PAGES: --> <span style="color:#900; font-size:16px">Extra web pages:</span> <br /> <input type="radio" name="extrapages" value="0" onClick="chkrads('extrapages')"> <b>Not for now</b> <input type="radio" name="extrapages" value="1" onClick="chkrads('extrapages')"> <b>1</b> <input type="radio" name="extrapages" value="2" onClick="chkrads('extrapages')"> <b>2</b> <input type="radio" name="extrapages" value="3" onClick="chkrads('extrapages')"> <b>3</b> <input type="radio" name="extrapages" value="4" onClick="chkrads('extrapages')"> <b>4</b> <input type="radio" name="extrapages" value="5" onClick="chkrads('extrapages')"> <b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Extra email addresses:</span> <br /> <!-- EXTRA EMAIL ADDRESS: --> <input type="radio" name="extraemail" value="0" onclick="chkrads('extraemail')"><b>Not for now</b> <input type="radio" name="extraemail" value="11" onClick="chkrads('extraemail')"><b>1</b> <input type="radio" name="extraemail" value="12" onClick="chkrads('extraemail')"><b>2</b> <input type="radio" name="extraemail" value="13" onClick="chkrads('extraemail')"><b>3</b> <input type="radio" name="extraemail" value="14" onClick="chkrads('extraemail')"><b>4</b> <input type="radio" name="extraemail" value="15" onClick="chkrads('extraemail')"><b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Image Bundles:</span> <br /> <!--Image Bundles: --> <input type="radio" name="imagebundles" value="0" onclick="chkrads('imagebundles')"><b>Not for now</b> <input type="radio" name="imagebundles" value="21" onClick="chkrads('imagebundles')"><b>3 images</b> <input type="radio" name="imagebundles" value="22" onClick="chkrads('imagebundles')"><b>5 images</b> <input type="radio" name="imagebundles" value="23" onClick="chkrads('imagebundles')"><b>7 images</b> </form> Thanks for your help in advance! Code: for(i=0;i<document.getElementsByName('checkresult_".$i."').length;++i){ if(document.getElementsByName('checkresult_".$i."')[i].checked){ thisurlext+=document.getElementsByName('checkresult_".$i."')[i].value; checkedlength++; if(i+1<document.getElementsByName('checkresult_".$i."').length){ if(document.getElementsByName('checkresult_".$i."')[i+1].checked){ thisurlext+='+'; } } } }; Let's say I check verses 1, 2, 3, 6 I want the Javascript not to ignore the + between the 3 and the 6: Code: <div id="txt_kjv0_1_1_0" style="float: left; background-color: rgb(234, 232, 200); margin: 0px; width: 178px; height: 497px; border: 1px solid rgb(122, 16, 16); padding: 5px 5px 0px; overflow-y: auto; overflow-x: hidden;"> <input id="sc0" value="kjv" type="hidden"> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_0" name="checkresult_0" onclick="" value="1" type="checkbox"><span style="font-weight: bold; margin: 2px;">1</span>In the beginning God created the heaven and the earth.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_1" name="checkresult_0" onclick="" value="2" type="checkbox"><span style="font-weight: bold; margin: 2px;">2</span>And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_2" name="checkresult_0" onclick="" value="3" type="checkbox"><span style="font-weight: bold; margin: 2px;">3</span>And God said, Let there be light: and there was light.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_3" name="checkresult_0" onclick="" value="4" type="checkbox"><span style="font-weight: bold; margin: 2px;">4</span>And God saw the light, that it was good: and God divided the light from the darkness.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_4" name="checkresult_0" onclick="" value="5" type="checkbox"><span style="font-weight: bold; margin: 2px;">5</span>And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_5" name="checkresult_0" onclick="" value="6" type="checkbox"><span style="font-weight: bold; margin: 2px;">6</span>And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</p> Hi I am trying to load html stream directly into webbrowser in delphi. The html contains java script. It loads xml and xsl files and display the xml content in the web browser. I got an error, says access denied for the command xmlDoc.load(fname); If I save the html into a file, test.html, and double click it, it is fine, no problem. The code is actually copied from w3schools.com. the html code as followed: <html> <head> <script> function loadXMLDoc(fname){var xmlDoc; if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else { alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } function displayResult() { xml=loadXMLDoc("catalog.xml"); xsl=loadXMLDoc("catalog.xsl"); if (window.ActiveXObject) { ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } } </script> </head> <body id="example" onLoad="displayResult()"> </body> </html> The delphi code is procedure TForm1.WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ; var v: OleVariant; HTMLDocument: IHTMLDocument2; begin memo1.Lines.LoadFromFile('d:\test\htmltxtold.html'); HTMLCode := memo1.Text; WebBrowser1.Navigate('about:blank') ; HTMLDocument := WebBrowser.Document as IHTMLDocument2; v := VarArrayCreate([0, 0], varVariant); v[0] := HTMLCode; HTMLDocument.Write(PSafeArray(TVarData(v).VArray)); HTMLDocument.Close; end; Thanks a lot suggestions welcome !!
This is my first post. I am reading "Javascript The Good Parts" ~ The Method Invocation Pattern Page 28 and tried this, var myObject= { value:0, increment:function(inc){ this.value+= typeof inc==="number" ? inc:1; } } myObject.increment(2); alert(myObject.value); but alert(myObject.value); is returning a value of "2", when it should return "3". Can someone help? Reply With Quote 12-22-2014, 09:59 AM #2 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts 0+2=2, not 3; the code is working correctly. Hi - in editing a website...this javascript html is really getting on my nerves - can somebody please tell me why i keep getting the error message expected ")" when i try this code: (which ive fiddled around with bloody loads to try and resolve!) <SCRIPT LANGUAGE=JAVASCRIPT > var r_text = new Array (); r_text[0] = Text 0; r_text[1] = Text 1; r_text[2] = Text 2; var i = Math.floor(3*Math.random()); { document.write("<marquee style="font-family: 'Georgia'; color: #FFFF00; font-size: 13pt; mso-fareast-font-family: 'Arial'" ><scrollamount="15"><b>" + r_text[i] + "</b></scrollamount></marquee>"); } it seems fine to me and is getting me really frustrated now any help greatly appreciated, do whatever you like to the coding if itll work! thankyou very much, joe. I am pretty novice. I do not know much about the compilers or how these things run. I do however have a good eye for trends and can figure just about anything out by looking at it. With that; I have a game that uses a exe launcher with a built in patcher. I have found the code for the launcher. There are several "jquery" scripts for basic components like scroll wheel. There are also things like "downloader.js", "inputs.js". I am interested in seeing what (and more precisely how many) ip addresses are being retrieved. I fear this patcher is using a hidden bittorrent like download system. The code for "downloader" is pretty basic. It clearly uses some other script, but I am wondering if you can point me in the direction of a utility to monitor running JS so that I can see what is being returned. Code: _Downloader = function() { this.downloadStatusCallback = null; } _Downloader.prototype = { setDownloadStatusCallback: function(callback) { this.downloadStatusCallback = callback; }, addDownload: function(downloadName, metaUrl, outputPath, authorizationURL) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('addDownload', 'string:' + downloadName + '|' + 'string:' + metaUrl + '|' + 'string:' + outputPath + '|' + 'string:' + authorizationURL + '|'); }, removeDownload: function(downloadName) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('removeDownload', 'string:' + downloadName + '|'); }, getDownloadOption: function(downloadName, optionName) // returns string { return document.SSNLauncher.SSNLauncher_ReturnString('getDownloadOption', 'string:' + downloadName + '|' + 'string:' + optionName + '|'); }, setDownloadOptions: function(downloadName, enableBitSources, enableWebSources) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('setDownloadOptions', 'string:' + downloadName + '|' + 'bool:' + enableBitSources + '|' + 'bool:' + enableWebSources + '|'); }, getDownloadActive: function(downloadName) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('getDownloadActive', 'string:' + downloadName + '|'); }, setDownloadActive: function(downloadName, active) // returns bool { return document.SSNLauncher.SSNLauncher_ReturnBool('setDownloadActive', 'string:' + downloadName + '|' + 'bool:' + active + '|'); } } function __Downloader_reportdownloadStatus(downloadName, state, active, totalBytes, bytesLeft, maxIncoming, averageIncoming, currentIncoming, maxOutgoing, averageOutgoing, currentOutgoing, bytesRead, bytesSent, scanBytesLeft) { if (SSN.Downloader.downloadStatusCallback != null) { SSN.Downloader.downloadStatusCallback(downloadName, state, active, totalBytes, bytesLeft, maxIncoming, averageIncoming, currentIncoming, maxOutgoing, averageOutgoing, currentOutgoing, bytesRead, bytesSent, scanBytesLeft); } } I have tried on several occasions to teach myself programing. I can get the commands and syntax fairly easily, and I am pretty good at 'coming up' with ways to get something done. I just don't have experience in this field (I'm in medical school) so I do not know about the tools and utilities programers use and scouring the internet has been less than fruitful. Anybody capable of pointing me in the direction of finding a utility to monitor running js (if that is even possible =/). I use dreamweaver CS5 to explore js code. -------------------------------------------------------------------------------- Can some1 help me at this, i am very new to javsciprt and HTML things, so as the title says, a simple bold to the selected text in a div is what i need. below is the div area i have, so how do it?? Code: <TD colspan="25" width="525px" style="text-overflow: ellipsis; overflow: hidden;"> <input type="hidden" $acmForms.bindText("casecomments") /> <div #if (!$acmForms.getFormAttributes().isReadOnly()) CONTENTEDITABLE #end onKeyUp="dairy_limitTextArea(this, 4000)" onKeyDown="dairy_limitTextArea(this, 4000)" id="spell_casecomments" style="width:800px; height:220px; overflow: auto; border: 1px solid #bdcee5;"> </TD> Hello , here is my code(which is not working on my problem) i want to remove anchor tag(href="a") will u please help.... Code: <html> <head><title>Welcome to DevForum</title></head> <script language="javascript" type="text/javascript"> function Remove() { var anchor = document.getElementsByTagName("a"); var i; for(i=0;i<anchor.length;i++) { var anc=anchor.item(i); var href=anc.attributes.getNamedItem("href"); if (href.value == "a") { anchor.item(i).attributes.getNamedItem("href").value = ""; } } } </script> <body onload="Remove()"> <h1>Welcome</h1> <a href="b">b</a> <a href="a">a</a> </body> </html> Thanks in Advance.... I am in the process of learning 'JavaScript' and I am having a problem understanding how to delete cookies. I understand that to do delete a cookie you want to set the expiration attribute of the cookie to delete, to any date in the past. My confusion lies in the exact syntax of how to do this. In the example s I have seen in books and on the internet it appears that you must submit the "exact" name/value pair that you originally set the cookie with to delete it. For an example: var UserId = "MrJones", password = "secret"; var currentDate = new Date(); currentDate.setFullYear(currentDate.getFullYear()+1); document.cookie = encodeURI("userid=" + UserId " + "; " + "password=" + password + "; expires=" + currentDate.toUTCString()); What is the minimum syntax I would need to delete the cookie above? Also, I need clarification on the terminology. Is a single cookie a collection of name/value pairs(also known as crumbs) or is each name/value pair considered a cookie unto itself? Why does the ECMA board allow people on drugs to be part of settings standards for programming languages that will be used by the entire world? I've been reading a book on JavaScript and have had no problems understanding anything until reaching Chapter 9 and the subject of cookies. This syntax is crazy. And the way you add to a cookie by using just an assignment operator? How about a cookie.Add() and a cookie.Delete() method? Hi, Please i am confuse to know the work of this sign (!)...which is exclamation sign in programming. i have this code here which which i remove the exclamation sign (!)..it dont work but when i add it ,then it work. Here is the code <script type="text/javascript"> function getvalue() { var mytextfield=document.getElementById("mytext"); if(mytextfield.value!="") { alert("You Entered:"+mytextfield.value) } else{ alert("would you enter some text") } } </script> <input type="text" id="mytext" size="30"> <input type="button" value="check" onclick="getvalue()"> Please help me to understand the use of this sign !. Thank you. Clement Osei. I am trying to add a pulldown menu with a button to my website. I have successfully done this with a javascript I found online here to give credit: http://www.blazonry.com/javascript/js_menu.php I tried to modify the form so it will use an image file instead of the default button. To troubleshoot I took the relevant code and put into a seperate html file. This one is using the default code from the site referenced above. This is the page published online: http://www.keylimecomputerservice.com/test/default.html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <SCRIPT LANGUAGE="JavaScript"><!-- function openURL() { // grab index number of the selected option selInd = document.theForm.aaa.selectedIndex; // get value of the selected option goURL = document.theForm.aaa.options[selInd].value; // redirect browser to the grabbed value (here a URL) top.location.href = goURL; } //--> </SCRIPT> </head> <body> <TABLE SPAN="3" BORDER=1 CELLSPACING=0 CELLPADDING=0 align="center" WIDTH="60%"> <TR> <TD WIDTH="33%"> <center><font color="black">Choose a connection</font></center><br> <form name="theForm"> <tt> <center> <select name="aaa" size="1"> <option selected value="#"> ---------- </option> <option value="/remote/connect1.exe">Connection 1</option> <option value="/remote/connect2.exe">Connection 2</option> <option value="/remote/connect3.exe">Connection 3</option> <option value="/remote/connect4.exe">Connection 4</option> <option value="/remote/connect5.exe">Connection 5</option> <option value="/remote/connect6.exe">Connection 6</option> <option value="/remote/connect7.exe">Connection 7</option> <option value="/remote/connect8.exe">Connection 8</option> </select> </center> </TD> <TD WIDTH="33%"> <input type="button" value=" GO " onClick="openURL()"> </tt> </form> </TD> <TD WIDTH="33%"> </TD> </TR> </TABLE> </body> I then tried to change the form to use an image instead of the default button. Obviously I didn't do it right. THIS ONE DOES NOT WORK. When you choose a menu item and then click the image, it just refreshes the page. Published page: http://www.keylimecomputerservice.co.../modified.html This is the modified code.: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <SCRIPT LANGUAGE="JavaScript"><!-- function openURL() { // grab index number of the selected option selInd = document.theForm.aaa.selectedIndex; // get value of the selected option goURL = document.theForm.aaa.options[selInd].value; // redirect browser to the grabbed value (here a URL) top.location.href = goURL; } //--> </SCRIPT> </head> <body> <TABLE SPAN="3" BORDER=1 CELLSPACING=0 CELLPADDING=0 align="center"> <TR> <TD WIDTH="33%"> <center><font color="black">Choose a connection</font></center><br> <form name="theForm"> <tt> <center> <select name="aaa" size="1"> <option selected value="#"> ---------- </option> <option value="/remote/connect1.exe">Connection 1</option> <option value="/remote/connect2.exe">Connection 2</option> <option value="/remote/connect3.exe">Connection 3</option> <option value="/remote/connect4.exe">Connection 4</option> <option value="/remote/connect5.exe">Connection 5</option> <option value="/remote/connect6.exe">Connection 6</option> <option value="/remote/connect7.exe">Connection 7</option> <option value="/remote/connect8.exe">Connection 8</option> </select> </center> </TD> <TD WIDTH="33%"> <input type="image" src="connectbutton.jpg" onClick="openURL()"> </tt> </form> </TD> <TD WIDTH="33%"> </TD> </TR> </TABLE> </body> Any and all help is appreciated. Runout74 Hi I have developed an internet mapping site which uses an html viewer with various frames to pull in a mapping window, a legend / key and a frame of tools amongst other things. It works absolutely fine in Internet Explorer version 6, but whilst testing it in Internet Explorer 7, my mapping window is not loading up the image. It might seem strange me posting this in a javascript forum but as the error is javascript related I thought I would give it a shot! The error message I am receiving is "Access is denied". After looking online, it appears as though this error could be linked to the use of frames; and those frames trying to access other windows with different document domains?? Does anyone know if new security measures have been implemented in IE7 which restricts the use of frames? My code is below; does anyone notice anything that might give this kind of javascript error? Any help will be greatly appreciated as I do not tend to dable too much in javascript! Code: <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <TITLE>Intranet GIS Service</TITLE> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript" SRC="javascript/aimsResource.js" TYPE="text/javascript"></SCRIPT> <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> // Designer will set the next variable - theTitle //var theTitle = "Intranet GIS"; var theTitle = ""; if (theTitle.indexOf("###TITLE##")!=-1) theTitle = titleList[0]; var cmdString = document.location.search; var webParams = cmdString; var reloadTimer=0; document.writeln("<TITLE>" + theTitle + "</TITLE>"); function doIt() { MapFrame.useJava=false; MapFrame.checkParams(); } function replacePlus(inText) { var re = /\+/g; inText = inText.replace(re," "); return inText; } function reloadApp() { //window.clearTimeout(reloadTimer); //reloadTimer = window.setTimeout("document.location.href = 'viewer.jsp' + cmdString",1000); //Above code replaced with this. Only the map should refresh after a resize, otherwise //all added datashare layers are lost. MapFrame.mWidth = MapFrame.getMapWidth(); MapFrame.mHeight = MapFrame.getMapHeight(); MapFrame.sWidth = screen.width; MapFrame.sHeight = screen.height; MapFrame.loadBannerLeft = parseInt((MapFrame.mWidth - 119)/2); MapFrame.loadBannerTop = parseInt((MapFrame.mHeight - 72)/2); MapFrame.document.getElementById("theMap").style.width = MapFrame.sWidth; MapFrame.document.getElementById("theMap").style.height = MapFrame.sWidth; MapFrame.iWidth = MapFrame.mWidth; MapFrame.iHeight = MapFrame.mHeight; MapFrame.legHeight = MapFrame.iHeight - 160; var cmd = 'MapFrame.sendMapXML();'; cmd += 'MapFrame.document.getElementById("theImage").style.width = MapFrame.mWidth;'; cmd += 'MapFrame.document.getElementById("theImage").style.height = MapFrame.mHeight;'; window.clearTimeout(reloadTimer); reloadTimer = window.setTimeout(cmd,1000); } </SCRIPT> </HEAD> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> var browser = navigator.appName; var moreStuff = 'onresize="reloadApp()"'; var addNS = 0; if (browser=="Netscape") { addNS = 3; } document.writeln('<FRAMESET ROWS="' + (45+addNS) + ',*,30,0" FRAMEBORDER="No" FRAMESPACING="0" onload="doIt()" BORDER=2 ' + moreStuff + '>'); document.writeln('<FRAME NAME="TopFrame" SRC="topbar.htm" MARGINWIDTH="5" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE>'); document.writeln('<FRAMESET COLS="' + (30+addNS) + ',*,270" FRAMEBORDER="No" FRAMESPACING="0" BORDER="2">'); </SCRIPT> <FRAME NAME="TextFrame" SRC="text.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE FRAMESPACING="0" BORDER="2"> <!-- If textframe is used--> <FRAMESET ROWS="*,115"> <FRAME NAME="MapFrame" SRC="MapFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="Yes" RESIZE="YES"> <FRAME NAME="ToolFrame" SRC="blank.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="Auto" FRAMEBORDER="No" RESIZE="YES"> </FRAMESET> <!-- If textframe is not used --> <!--<FRAME NAME="MapFrame" SRC="MapFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" RESIZE="YES">--> <FRAME NAME="TOCFrame" SRC="TOCFrame.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="Auto" FRAMEBORDER="No" RESIZE="YES"> </FRAMESET> <FRAMESET COLS="400,*" FRAMEBORDER="Yes" BORDER=2 FRAMESPACING="0"> <FRAME NAME="ModeFrame" SRC="bottom.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE> <FRAME NAME="ModeFrame" SRC="bottom.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE> </FRAMESET> <FRAME NAME="PostFrame" SRC="jsForm.htm" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="No" FRAMEBORDER="No" NORESIZE FRAMESPACING="0" BORDER="2"> </FRAMESET> <NOFRAMES> <BODY> <P> </BODY> </NOFRAMES> </HTML> Code: <script type="text/javascript"> function loadText() { var t1=setTimeout("document.getElementById('data').innerHTML='<center><img style=\"margin-top:30px;\" src=\"loading.gif\" /></center>'",0000); var t2=setTimeout("document.getElementById('data').innerHTML='THEPAGE'",6000) } </script> The above is in the header, and I'm calling it in the html. Code: <script type="text/javascript"> document.write(loadText()); </script> in the page it displays properly, but then it also says "undefined" not sure why? anyone have any ideas? Hey everyone, Below is the code for a javascript timer. I don't understand why the way I'm using the windows object setInterval isn't working. I've highlighted the problematic areas. Please have a look. Code: function timer() { var display = document.getElementById('countdown'); //creates the dom by getting span with id of "countdown". var time = new Date(60*10*1000); function zeroPad(number) { //places a 0 in front of the number if it's less than 10. For example 09 or 08. if (number<10) return '0' + number; else return number; }; function interval() { var min = zeroPad(time.getMinutes()); var sec = zeroPad(time.getSeconds()); display.innerHTML = min + ":" + sec ; //Displays the time in the span with the id of "countdown". time.setSeconds(time.getSeconds()-1); if (time < 0) { alert("Times UP"); break; } }; window.setInterval(interval(), 1000); //Why isn't the setInterval working once the timer is initiated?!!! } window.onload = timer; //initiates the function I don't understand why the setInterval isn't working. It should be calling the function every second- what's wrong with the code? Thanks! Hi, I'm having some issues turning this "Please Wait"/Disabled button into a function. Code: <input type="submit" value="Submit Form" onClick="this.disabled = 'true'; this.value='Please wait...';" /> Code: function pleasewait() { this.disabled = 'true'; this.value='Please wait..' } <input type="submit" value="Submit Form" onClick="pleasewait();" /> Thanks much Hi all, I have an <img> place holder in my HTML, and when users 'onclick' different button's, a javascript function is called that makes different images appear within the <img> place holder. ie. the src changes. See below: Code: <body> <img id="image_space" src="" /> <button type="button" onclick="imageChange(/image1.jpg)">Image 1</button> <button type="button" onclick="imageChange(/image2.jpg)">Image 2</button> <script> function imageChange(image){ document.getElementById("image_space").src=image; } </script> </body> Strait forward enough. I also have a third button, which activates a different javascript function to display an image within a different <img> place holder. BUT, I only want this button to work IF "/image2.jpg" is the ACTIVE image within the original <img> place holder (with id="image_space"). How can I write some javascript code that will identify that image as being ACTIVE? The final code with the missing "link" is described below: [CODE] Code: <body> <img id="image_space" src="" /> <img id="image_space2" src="" /> <button type="button" onclick="imageChange(/image1.jpg)">Image 1</button> <button type="button" onclick="imageChange(/image2.jpg)">Image 2</button> <button type="button" onclick="thirdImageChange(/image3.jpg)">Image 3</button> <script> function imageChange(image){ document.getElementById("image_space").src=image; } function thirdImageChange(thirdImage){ if (missing code here that says "/image2.jpg ACTIVE in <img id="image_space">) { document.getElementById("image_space2").src=thirdImage; } } </script> </body> Sorry it's so long winded! I hope I made it clear enough. Your help would be GREATLY appreciated. Thanks for reading! |