JavaScript - Using Document.writeln()
I'm sorry if this question seem very basic but I just start learning javascript.
I would like to display an image but not sure why it is not working. In a nutshell, here's my code Code: <html> <head></head> <body> <script type="text/javascript"> document.writeln("<img src=/"xMark.jpg /" width=25 height=25 >");</script> </body> </html> Similar TutorialsNot sure why this is not working but can someone see my error. <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>HomeWork3Part2</title> <script type="text/javascript"> function finalPay(grossPay){ var federalTax = num.tofixed(2)(grossPay * (.31)); var stateTax = num.tofixed(2)(grossPay * (.08)); var localTax = num.tofixed(2)(grossPay * (.02)); var finalPay = (grossPay - (federalTax + stateTax + localTax)); return finalPay; } </script> </head> <body> <script type="text/javascript"> var grossPay = parseInt(prompt("Enter your Gross Pay Amount", "400")); document.writeln(finalPay(grossPay) + " Is your amount of your check after taxes are taken out"); </script> </body> </html> Probably a stupid noob question, is there any way I can stop document.write from outputting info to a new page I would prefer to have it shown in a textarea. Info from an array that is suppose to display in a text area when button is clicked and when another button is clicked it is suppose to show some other info. But what happens is the first info displays in textarea for a few seconds and then the second info is displayed but on a new page and not the textarea where I want it to go I have marked code within the code // I want this specific code to be displayed second but I know its in the wrong spot. Here is the code [CODE] function show() { var myArray = new Array(); myArray[0] = document.getElementById('fullname').value; ' myArray[1] = document.getElementById('address').value; myArray[2] = document.getElementById('phone').value; myArray[3] = document.getElementById('email').value; //Code I want to display second in the textarea //var string = myArray.join("\n") //document.getElementById('textarea').value = string; document.writeln('Thank you for registering,' + ' ' + myArray[0] + '. Your membership will be confirmed by E-mail to ' + myArray[2] + "<br>"); document.writeln('Registration Details:') document.writeln("<br>") for (var i=0; i<myArray.length; i++) { document.write(myArray[i] + "<br>"); } } [\CODE] Thanks in advance My code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> I found this line in one of the scripts on javascript.kit <code> if(document.layers|| document.getElementById|| document.all) </code> Could someone give me an idea on why this line would be used in a code? Thank you very much I'm working on a website that will basically embed a widget/frame sent by a handler into a user's current page. The user basically adds a script tag to where they would like the HTML to be. The script tag has their settings and is basically a document.write that calls all the code that we want displayed. So here's my problem. We have a map that we need to add in a specific section, and to get the map we have to call another script tag. So we end up having a script tag (map) embedded in another script tag (the code for the widget/frame) or we end up having to document.write inside a document.write. Now this works just fine and as expected in Firefox, Safari, and Chrome. However, Internet Explorer and Opera wait until the first document.write is completely finished before calling the embedded one. Of course the problem with this, is that it takes the map out of the document's flow and just appends it to the bottom left of the page. Since the rest of the page has already been called, there's no way to move the interior "map" script. Any ideas? Basically just trying to figure out how (if even possible) to render an embedded script tag in Internet Explorer and be able to place it properly. I've tried everything that I can think of, including AJAX and Google's unescape script. Any suggestions, I'd greatly appreciate it. Or even if you've encountered a similar problem, and know that it just isn't possible in IE or Opera, that would be fine too. Thanks in advance! I am writing some javascript that when the user clicks on a link, it hides or displays content inside a div tag. I have been trying to add some code that would only allow for one div tag to be displayed at a time. Here is where I originally got the code (http://www.willmaster.com/library/hi...-to-reveal.php) Whenever I run this code I get this error: Code: Error: document.getElementById(months[x]) is null Source File: /resources/default.js Line: 30 This is the JavaScript that runs when the user clicks the link: Code: <!-- function accordion(tid) { var x; var months = new Array(); months[0]="January"; months[1]="February"; months[2]="March"; months[3]="April"; months[4]="May"; months[5]="June"; months[6]="July"; months[7]="August"; months[8]="September"; months[9]="October"; months[10]="November"; months[11]="December"; for (x in months) { document.getElementById((months[x])).style.display = "none"; } if(document.getElementById(tid).style.display == "none") { document.getElementById(tid).style.display = ""; } else { document.getElementById(tid).style.display = "none"; }} //--> Here is where the javascript is activated from PHP Code: <a href=javascript:accordion('$month2');>$month2</a><br /> <div id='$month2' style='display: none';> Hello $month2 </div> What is an alternative to document.write? I know I could use <p> in html </p> I would like to use JS though. I hope you can understand my question. I am 14yo and this is not for homework. I just wanna try and learn JS. I read document.write can cause me problems. But all I ever see is: <script type="text/javascript"> document.write("any words"); </script> what alternate could I use? Hello, I'm new to Javascript. I know how to make a script that when you click on a button it changes a variable. I also know that with document.write I can express this variable but I do not know how to refresh document.write! For example, if I have a var car =3 and when I click on a button car++ (or increases by 1 so it becomes 4 then 5 and so forth depending how many times you click the button) and I write document.write (car), it only shows the 3 and no matter how many times I click on the button, the 3 doesn't change. How can I get the document.write to show the updated variable? Thanks! So I want to have a button that when I click it will change this variable and that number will change live on the page. i want to search the index.xml file throu diff input like combo box and input text shown in the search.html file and output the result in a tale. search.html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Search</title> <script type="text/javascript" src="search%20xml/search%20xml%20with%20mouseover%20table/searchindex.js"></script> </head><body> <form name="frmMain" id="frmMain" action=""> <b>Search Document: <br> <br> <br> Choose Book <select name="Select1"> <option selected="">--All--</option> <option>b1</option> <option>b2</option> </select><br> <br> Choose year <select name="Select2"> <option selected="">--All--</option> <option>1979</option> <option>1980</option> </select><br> </b><br> <strong>Doc_No</strong> <input name="Text1" type="text"><br> <br> <strong>Subject</strong> <input name="Text2" type="text" style="width: 356px"><br> <br> <input value="Submit" onclick="searchIndex(); return false;" type="submit"> </form> </body> </html> index.xml Code: <?xml version="1.0" ?> <books> <book name="b1"> <year date="1979"> <Document Doc_No="17" Subject="s1" path="ta3amime\1979\17_1979.tif">17_1979_s1.tif</Document> <Document Doc_No="18" Subject="s2" path="ta3amime\1979\18_1979.tif">18_1979_s2.tif</Document> </year> <year date="1980"> <Document Doc_No="19" Subject="s3" path="ta3amime\1980\19_1980.tif">19_1980_s3.tif</Document> <Document Doc_No="6" Subject="s4" path="ta3amime\1980\6_1980.tif">6_1980_s4.tif</Document> <Document Doc_No="1" Subject="s5" path="ta3amime\1980\1_1980.tif">1_1980_s5.tif</Document> <Document Doc_No="7" Subject="s6" path="ta3amime\1980\7_1980.tif">7_1980_s6.tif</Document> <Document Doc_No="4" Subject="s7" path="ta3amime\1980\4_1980.tif">4_1980_s7.tif</Document> </year> </book> <book name="b2"> <year date="1979"> <Document Doc_No="8" Subject="s8" path="ta3amime\1979\8_1979.tif">8_1979_s8.tif</Document> <Document Doc_No="7" Subject="s9" path="ta3amime\1979\7_1979.tif">7_1979_s9.tif</Document> </year> <year date="1980"> <Document Doc_No="9" Subject="s10" path="ta3amime\1980\9_1980.tif">9_1980_s10.tif</Document> <Document Doc_No="1" Subject="s11" path="ta3amime\1980\1_1980.tif">1_1980_s11.tif</Document> <Document Doc_No="8" Subject="s12" path="ta3amime\1980\8_1980.tif">8_1980_s12.tif</Document> <Document Doc_No="14" Subject="s13" path="ta3amime\1980\14_1980.tif">14_1980_s13.tif</Document> <Document Doc_No="16" Subject="s14" path="ta3amime\1980\16_1980.tif">16_1980_s14.tif</Document> </year> </books> searchindex.js Code: window.onload = loadIndex; function loadIndex() { // load indexfile // most current browsers support document.implementation if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.load("index.xml"); } // MSIE uses ActiveX else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("index.xml"); } } // What would be the searchIndex() function ????? // Result in a table I have a html file and a separate javascript file. The html file contains: <input type="reset" id = "resetButton" /> I want a message to pop up if the reset button is pressed. So in the js file I have: document.getElementById("resetButton").onclick = doAlert; doAlert is a function that simply does: alert("Do you want to reset?"); I know my separate js file is linked correctly because if I just put in alert("hello"); in the js file then it works. But if I use the document.getElementById thing in the js file, then there is an error. The error, according to the error console, says that "resetButton" is null. Can someone help me? thanks! btw, I'm totally new to programming...and I need to do this for my homework assignment Hi, I am trying to create a xml document and load it into a 3rd party function as follows: Quote: var doc = new ActiveXObject('Microsoft.XMLDOM'); // OR var doc = document.implementation.createDocument('', 'xml', null); o.overlayKML('somefile.xml'); // Works perfectly o.overlayKML(doc); // Doesn't work at all, return unsupport error I get to know that the overlayKML (3rd party function) needs to read a physical file with a path and sadly it doesn't support DOM. How can I create a javascript document that mimic a physical file and introduce it into the function? Thanks! Hello everyone. I'm having a little problem with creating a element in internet explorer. The element that I'm creating is a div with a few style attributes to to it. The div is suppose to cover the whole page almost like a black transparent window on the page. However it is not. The messed up part about this is that it works fine in Firefox, google chrome and I'm sure other browsers (though haven't tested) and when I go to apply the div in my actual code as javascript is suppose to when you tell it create it, it works fine. No problems whatsoever... I'm not to sure what I'm doing wrong here and it would be great if I could get some help with this. Thanks Code: function showPhotoUpload() { var overlay = document.createElement("div"); overlay.setAttribute("style","z-index:3; background:#111111; width:100%; height:100%; position:absolute; top:0; opacity:0.5; filter:alpha(opacity:50);"); document.body.appendChild(overlay).lastChild; } Dear Great Coders, I am having some trouble to get the id of the parent of a document which is iframe1 here. As you can see it the <javascript> is residing in the javascript section. Do mind giving me some ideas? Yes, I know. I can insert the javascript on the top, but believe me i cant for some purpose because I am intergrating many other codes into it. <html> <iframe id="iframe1"> <html> <head> <javascript> </head> <body> </body> </html> </iframe> </html> Code: document.getElemetById... is that it, or could be somehow done: Code: anyElement.getElemetById... ? Tryed and it did not work. Hi, I need to open a PDF file via a web page. Basically, I want to have a textbox where I type in a filename and then click submit and it will open that document. For example, I need to open a PDF document... I need to have a text box where I can input "test1" for example, click "GO" and it will add the "C:/test/" + textbox value + ".pdf" and open it in the browser. I could do it in PHP but this is going to run on a local machine with no serverside so I assume JS will be the way forward. Any ideas? Many Thanks MJFCAD I have this nice little piece of code that Bullant (CodingForum Senior Coder) helped me with. And it works flawlessly! I want to put it in the same document twice. I've tried to tweak the code so that each script is unique, but to no avail Both scripts work by themselves, but when placed together on the same page - the first one fails. Here is the test-site where it is being used: http://metrobilia.worldsecuresystems.com/stools.html# Here's what I'm doing (see below): Any help would be greatly appreciated! Code: <head> <link href="/stylesheets/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var picData = [ ['images/template2/fpo1_templ2.jpg','URL_for_one'], ['images/template2/fpo2_templ2.jpg','URL_for_two'], ['images/template2/fpo3_templ2.jpg','URL_for_three'] ]; //preload the images var oPics = []; for(i=0; i < picData.length; i++){ oPics[i] = new Image(); oPics[i].src = picData[i][0]; } function swapImage(obj){ oImgSwap.src = oPics[obj.indx].src; oImgSwap.parentNode.href = picData[obj.indx][1]; } window.onload=function(){ oImgSwap = document.getElementById('imgSwap'); oLinks = document.getElementById('radiobs').getElementsByTagName('a'); for(i=0; i < oLinks.length; i++){ oLinks[i].indx = i; oLinks[i].onclick=function(){ swapImage(this); return false; } } swapImage(oLinks[0]); } </script> <script type="text/javascript"> var picDatab = [ ['images/template2/fpo1_templ2b.jpg','URL_for_one'], ['images/template2/fpo2_templ2b.jpg','URL_for_two'], ['images/template2/fpo3_templ2b.jpg','URL_for_three'] ]; //preload the images var oPicsb = []; for(i=0; i < picDatab.length; i++){ oPicsb[i] = new Image(); oPicsb[i].src = picDatab[i][0]; } function swapImageb(obj){ oImgSwapb.src = oPicsb[obj.indx].src; oImgSwapb.parentNode.href = picDatab[obj.indx][1]; } window.onload=function(){ oImgSwapb = document.getElementById('imgSwapb'); oLinksb = document.getElementById('radiobsb').getElementsByTagName('a'); for(i=0; i < oLinksb.length; i++){ oLinksb[i].indx = i; oLinksb[i].onclick=function(){ swapImageb(this); return false; } } swapImageb(oLinksb[0]); } </script> </head> <div class="graphics_templ2" style="padding-left:217px;"> <div class="selections"> <div> <a href=""> <img src="" id="imgSwap" alt="" /> </a> </div> <div id="radiobs"> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_1_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_2_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_3_fpo.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> </div> </div> </div> <div class="graphics_templ2" style="padding-left:15px;"> <div class="selections"> <div> <a href=""> <img src="" id="imgSwapb" alt="" /> </a> </div> <div id="radiobsb"> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_1_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_2_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> <div class="single_box"> <a href="#"><img src="/images/template2/sample_box_3_fpob.jpg" width="30" height="30" alt="Sample Box Fpo"></a> <h2>Color 1</h2> </div> </div> </div> </div> What I'm trying to get are the tag ids separately after I call the callback function. I've been racking my brain for far too long on this one. Here is a shorter version of what I have. I'm using the array's length to count and break into their own lines. How do i get all 9 id="hover_[index]" separately using my array length? PHP Code: var info = Array("bla_1", "bla_2", "bla_3", "bla_4", "bla_5", "bla_6", "bla_7", "bla_8", "bla_9"); function callback(results, status) { if (status == myStatus) { for (var i = 0; i < results.length; i++) { send(results[i]); } } } function send(info) { document.getElementById('results').innerHTML += "<div id='hover_"+info.length+"'>Something</div>"; hover_target = document.getElementById('hover_'+info.length);// how do i get all 9 hover_[index] separately? someEvent.addDomListener(hover_target, 'mouseover', function() { // do something }); } Thank you so much in advance, Frank So i 've reviewed my work and can't see what i've done wrong. here is the html <code><html> <head> <title>Javascript Practic</title> <script type="text/javascript" src="Practice.js"> </script> </head> <body> write something here <div id="here"> blue here</div> </body> </html></code> and here is the javascript: <code> window.onload = tryInnerHTML; function tryAlert(){ alert("just trying it out"); } function tryInnerHTML(){ var p = document.createElement('p'); here = document.getElementById("here"); here.style.color = "blue"; p.innerHTML("<b>This is Dynamic</b>"); here.appendChild(p); } </code> firebug is saying the error is p.createElement('p'); but for the life of me I can't guess why any help would be very appreciative. Hello again, I've continued to study and work on JavaScript. I've had some problems with the document.write() function. When I try to do a math problem, the whole content of the page clears out and only displays the solution. For example: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script type="text/javascript"> function jahava() { var h = 1 var r = 4 var t = 5 document.write(h += r += t) } </script> </head> <body> <button OnClick="jahava()">Click Me!</button> </body> </html> So If I put other content, like the button I was displaying (which I wanted to stay visible), the function would make them all disappear. I would again appreciate any help towards this matter. Sincerely, Taro B. PS; This is not a calculator related problem, just in-general. I am trying to pass a value to a function autosuggest() f and i but i get the error... Message: Syntax error Line: 21 Char: 29 Code: 0 ajax_autocomplete2/ajax_search_for_airport_framework.js line 21 being q = ..... how do i correctly pass a value to the function and use it in the function to get the value of an element. Code: function autosuggest(f,i) { q = document.getElementById(f).value; .... } |