JavaScript - Line Breaks In Document.write Syntax
Hi I currently have this:
var d = new Date() var theDay = d.getDay() switch (theDay) { case 1: document.write("On Air Tonight...") <br> document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 2: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 3: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 4: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 5: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 6: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break case 7: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") break default: document.write("On Air Tonight...") document.write("ALAN POWELL!") document.write("8pm - 10pm") document.write("CARL KANE!") } Which obviously outputs the following: On Air Tonight...ALAN POWELL!8pm - 10pmCARL KANE! How do i code it so it displays On Air Tonight... ALAN POWELL! 8pm - 10pm CARL KANE! Also in Firefox, its not displaying ANYTHING... is there anything wrong in the code which FF would throw out? CSS validation says everything is ok any help would be fantastic. Thanks in advance UKD. Similar TutorialsI must have spent around 8 hours looking for the JavaScript code I need for putting text on the screen using onclick. Here is the code I found: http://javascript.internet.com/snipp...functions.html Code: /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Created by: HunBug | http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11430 */ function appendText(node,txt) { node.appendChild(document.createTextNode(txt)); } function appendElement(node,tag,id,htm) { var ne = document.createElement(tag); if(id) ne.id = id; if(htm) ne.innerHTML = htm; node.appendChild(ne); } That works great, but I need to add three lines of text at a time, not just one. I spent at least 4 more hours searching for ways to add a line break with JavaScript, but nothing I have found works with this code. Here's what the onclick code looks like: Code: onclick="appendText(document.getElementById('bb1'),'8,4,6' + '0,0,0' + '16'); <div id="bb1"></div> The page I'm working on will have clickable text and image maps and when you click, three lines of batari Basic code will be added to a DIV. Here's an example of what that code will look like: Code: 8,4,6 0,0,0 16 Click on another link and you'd see something like this: Code: 8,4,6 0,0,0 16 8,12,17 0,0,0 16 It would keep adding three lines of batari Basic code to the list every time you clicked. If somebody can figure out how to stick line breaks in this code that really work, I'll be all set. I have tried <BR>, \n, \r\n and a couple of other things, but nothing works so far. Thanks. I have a web page that works like the game Mastermind. The user enters 4 letters in a text box (each representing a colour). Then the computer checks if what the user enters is valid with 2 for loops. If it isn't a line needs to appear saying error, please try again. At the minute I can only get an alert to appear. This works fine but if the user enters 4 valid colours in then the computer will write whether they got a colour write but in the wrong place and if they got a colour write and in the right place (check the rules of Mastermind for more information). Ultimately, I need something that can write lines beneath the already existing lines. Would it be possibly to get the whole document, place it in an object, then rewrite the whole web page with the additional lines. There won't be any images on the web page, only text Thanks 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! 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> Hi i have a function (i wont write it out coz it is too long!) but after i have done the main calculations within this function i wont to display some of the variables in a table. i have writen: document.write( <table border="1"> <tr><td> Value 1 </td><td> document.write(a); //here * </td></tr> </table> ); were it says "here *" i wont to write within the table variable a (which i have defined properly in the function). However, as i have already written document.write it actually displays the text "document.write(a);" instead of the value for var a. Help asap please as it in for school soon! Thanks in advanced :D 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. 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? Below is a mock snippet of what I need. I think the issue is Code: document.write(b) because if I change that to an alert, it works fine. I thought I was using the proper syntax, but I guess I am not. Can anyone help a noob? Code: <html> <head> <script type="text/javascript"> function d(){ a=document.getElementById("txt1").value; if(a > 1){ b=a/100; document.write(b) } else{ b=a; alert(b) } } </script> </head> <body> <form name="form"> <h2>This is a form</h2> <input type="text" id="txt1" name="txt"/> type here <br /> <button type="submit" id="btn" onclick="d()">Submit</button> </body> </html> Im having an issue placing a document.write output in a specifc place (after my form), i want the document.write output to be produced from an if statement which is based on a variable within a function the document.write output is to be placed outside the script thought :S into another div CODE if (count<5) { document.write('unlucky') } any ideas? I Am trying to use the following script to generate a url dynamically and I can get the link working just fine with plain txt in the anchor area but when I try to add an image - I am running into trouble. Any help would be much appreciated! what is wrong with the following? <script>document.write ("<a href=\"http://contact."+ domain +"/ws/eBayISAPI.dll?ShowCoreAskSellerQuestion&requested="+ userid +"&iid="+ itemid +"&frm=284&redirect=0&SSPageName=PageAskSellerQuestion_VI\"><img src=\"http://www.thebluedot.net/images/layout/contact_us.gif\" style=\"border:none;\"></a>");</script> Please help me out. I have been tearing my hair out over this basic script. I am complete newbie to javascript so please be easy on me. Thanks for any help in advance. ------------------------ The Blue Dot pays top dollar for your used cell phones. 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. is there any alternative to document.write() which writes only in a specific part of document, does not overwrite whole document. and yeah, in this case the document.getElementById().innerHTML dosent work either, coz its in a loop, here's the code if you wanna see: Code: if (aa==1) { for (i=0;i<a.length;i++) { c = txt; b = a[i].childNodes[0].nodeValue; // a is already assigned someplace in a xml document. txt = (b==" T4 ")? "T4 <br />": ""; document.write(c); } } Note: in the above code, the code: Code: txt = (b==" T4 ")? "T4 <br />": ""; is same as (also can be written as ) the code : Code: if (b==" T4 ") { txt = "T4 <br />" ; } else { txt = "" ; } document.write("<table><tr><td><a href='#' onMouseOver='MM_swapImage('changeMe','','images/calNum/calNum4g.jpg',1);'><img id='changeMe' name='changeMe' src='images/calNum/calNum1.jpg' border='0'/></a></td></tr></table>"); basically the one thing I am know is a problem or at least where the problem starts is when the ","(comma) is added in the parathesis for the params of MM_swapImage. Whats the correct way to write those commas? Hey I'm having a problem with this line: Code: var val1 = document.sform.sel1.value; sform is the name of a form that the data is being put onto. Problem is I want to change that name to verifypage.php When I replace sform with the verifypage.php I believe (I have no clues on JS) that the . if the extension of verifypage.php is screwing the code up. It's a dynamic drop down list that I want to display the results on another page. Thanks! I am very new to JavaScript, however I already seem semi-stumped. The tutorial I am using, mentions that for tutorial example purposes they use document.write() however it suggests that I avoid using this as it will overwrite the whole HTML page. I know that I can use document.getElementById() for some things... however this begs my question: When do you use document.write(), when do you use document.getElementById() and is there also another method you use to change/write to the HTML Document using JavaScript? Otherwise, do you just use document.getElementById() quite a lot in JavaScript? Like I said, I'm very new to JavaScript, so it's all still very new to me. Cheers, Asher What other methods can I use to insert code into my HTML pages from an external file, that will be able to be picked up by search engines and will show entirely if you do a "View Source" on my page? I've been using document.write functions in my personal home page for doing things like maintaining nav. bars, footers, etc. However, the HTML that's written using document.write is not picked up by search engines being that its browser-side instead of server-side and if you view the source of the page, all it shows is the call to my JS function that does the document.writes. my arrays. how do i input them into the loop? firstName = new Array(); lastName = new Array(); street = new Array(); city = new Array(); state= new Array(); zip = new Array(); amount = new Array(); date = new Array() Code: <script type=text/javascript> var values = []; var SIZE = 10; document.write('<table class="mytable" border="1">'); for (var index = 1; index <= SIZE; index++) { document.write('<tr><td>'); values.push(Math.random()); document.write(values[values.length -1]); document.write('</tr></td>'); } document.write('</table>'); var sum = 0.0; for (var index = 0; index < values.length; index++) { sum += values[index]; } document.write('<table class="totaltable" border="1">'); document.write('<tr><td>Total Number of Rows</td></tr><td> Total Sum</td></tr>'); document.write('<tr><td>' + values.length + '</td></tr>' + sum + '</td></tr>'); ('</table>'); </script> Hello everyone, I am new I found this site while searching for help with my problem. I'm new to javascript and having a very hard time with the document.write. Can anyone tell me why I'm getting this error? Error: missing ) after argument list Source File: file:///G:/CINS%20157/tutorial.12/case1/clist.htm Line: 79, Column: 58 Source Code: document.write("<th id='sumTitle' colspan='2'>" Summary "</th>"); Then there is an arrow pointing between the S and u in Summary. Even if you could just tell me where to look for help with the answer that would be greatly appreciated. If it helps this is the code it is attached to: <script type="text/javascript"> document.write("<table border='1' cellspacing='1'>"); document.write("<tr>"); document.write("<th id='sumTitle' colspan='2'>" Summary "</th>"); document.write("</tr>"); document.write("<tr><th>" Contributors "</th>"); document.write("<td>"+amount.length+ "</td></tr>"); document.write("<tr>") document.write("<th>"); document.write(Amount); document.write("</th>"); document.write("<td>"+amountTotal()+"</td>"); document.write("</tr>"); document.write("</table>"); </script> Thanks in advance for any help you can give me. I really appreciate it. Hello everyone, I'm having trouble getting some spacing in my code. Here's my function below. Code: function buildResume() { resName = document.myResume.name.value resAddress = document.myResume.address.value resPhone = document.myResume.phone.value resEmail = document.myResume.email.value resInfo = document.myResume.info.value flyWindow = window.open() flyWindow.document.write(resName + "<br>" + resAddress + " / " + resPhone + "<br>" + resEmail + "<br>" + "<hr width=36% align=left>") flyWindow.document.write("Personal Information" + resInfo) } The part I'm trying to add spacing between this part. Code: flyWindow.document.write("Personal Information" + resInfo) It comes out as: Personal Information *whatever the value of resInfo is* I would like it so it reads as (underscores being the spaces): Personal Information________*whatever the value of resInfo is* I've tried using   but could not get it to work, maybe I'm using it wrong. If anyone could shed some light on this for me it'd really help. If you need to see some more of my code let me know too. document.write("<script type='text/javascript' src='http://www.website.com/javscript.js'></script>"); For some reason this will not output correctly. It ouputs "); Which is the last three characters. |