JavaScript - Simple Problem With Document.write() Driving Me Nuts!
How come when the page below loads, I see the "Ahh!" but not the "HELLO??".
The "Ahh!" is generated by the document.write() in JavaScript. Anytime I use it, the other HTML in the page seems to stop loading. Any thoughts? - - - - - - - <html> <head> <title>test</title> </head> <body> <script type="text/javascript"> window.onload = Scream; function Scream() { document.write("Ahh!!"); } </script> <br><br><br><br> HELLO?? </body> </html> Similar TutorialsHi all, I have a string which contains HTML and *possibly* IMG tags. I am trying to extract part of each IMG tag which may be in the string. The string is part of a chat-box message which may or may not contain smilies. Here is a typical line of text, without processing (note I mis-spell the bbcode "quote" so as not to fool this board): Code: [qoute="Krupski"]<img src="./images/smilies/smile.gif" alt=":smile:" title="smile" /> <img src="./images/smilies/thumbsup.gif" alt=":thumbsup:" title="thumbsup" /> <img src="./images/smilies/thumbsdown.gif" alt=":thumbsdown:" title="thumbsdown" />[/qoute] Notice that each image has an "ALT" attribute which contains the smiley code of the smiley image. THAT is what I want to extract. This is the regex I am using to grab each smiley code: Code: txt = txt.replace(/<img(?:.*?):(.*?):(?:.*?)\/>/gi,':$1:'); The weird thing is, the regex grabs the FIRST and LAST of the three, but not the middle one! I'm sure the stupid mistake is sitting right in front of my face, but I'm not seeing it. Any help will be greatly appreciated! Thanks. -- Roger Hi all, I'm working on an internal site for my company and I have a snippet of code that works 100% fine indepentantly but when I try to use it inside a document.write I can't get it to work. I'm pretty sure it's down to the structure of it but I'm inexperienced with JS so I'm not sure how do correctly structure it. Here is the code I want inside of a document.write(): Code: <a href='javascript: void(0);' style="text-decoration:none; font-size:14px;" onclick=" document.getElementById('my_hidden_div_id_1').innerHTML = '<iframe src=\'{file:link}\' width=\'880\' height=\'500\'></iframe>' $('#my_hidden_div_id_1').koverlay({title: '{file:filename}'}); $('.css_koverlay').css({'background-color':'#9c183a'}); ; "> Pop-Up</a> Could anyone help me correctly insert it inside document.write() so that it outputs without errors? Thanks! 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. 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! Hello, I have a problem with the following code! I want to use it so that customers check a checkbox under each photo they want, in a photo gallery, and when they finish, they can click and the photos they checked appear using document.write in a new page! The problem I have is that when the script finds the first image, it uses document.write, shows only the first image it finds and then ends the foor loop! How can I code it so that it finds all the photos first and then shows them in the new page! Here is the sample code, sorry for my bad English and thanks for your time! -------------------------------------------------------------------------- <script type="text/javascript"> function findphotos(test){ for (i=0; i<document.test.checkgroup.length; i++){ if (document.test.checkgroup[i].checked==true){ document.write('<img src="'+i+'.jpg">'); } } } </script> <form name="test"> <input type="checkbox" name="checkgroup" /> <input type="checkbox" name="checkgroup" /> <input type="checkbox" name="checkgroup" /> </form> <h1 onclick="javascript:findphotos(test)">Find</h1> 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> If the value is negative it should be in red, otherwise it should be in green. It looks like JavaScript completely ignores the css class. Help please. Code: <html> <head> <title>Prva</title> <style type="text/css"> span.Pozitivno { color:green; font-weight:bold; } span.Negativno { color:red; font-weight:bold; } </style> <script type="text/javascript"> function vpisi_stevila() { var a; var b; //Vnos spremenljivk a=prompt("Vnesi stevilo a:") b=prompt("Vnesi stevilo b:") a=a*1 //S tem spremenimo string v int b=b*1 //Izpis stevil if(a<0) { document.write("A:<span class='Negativno'> " + a + " </span> <br />"); } else { document.write("A:<span class='Pozitivno'> " + a + " </span> <br />"); } if(b<0) { document.write("A:<span class='Negativno'> " + a + " </span> <br />"); } else { document.write("A:<span class='Pozitivno'> " + a + " </span> <br />"); } document.write("Vsota:", a+b, "<br />"); document.write("Razlika:", a-b, "<br />"); document.write("Mnozenje:", a*b, "<br />"); document.write("Deljenje:", a/b, "<br />"); document.write("Ostanek:", a%b, "<br />"); if(a>b) //Ce je A vecje od B { document.writeln("A je <b>večje </b> od b") } if(a<b) //Ce je B vecje od A { document.writeln("A je <b>manjse </b> od b") } if(a==b) //Ce sta enaka { document.writeln("A je <b>enako </b> b") } } </script> </head> <body onload="vpisi_stevila()"> </body> </html> 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 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. 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. 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. 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. 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. Hello, I have the following code, which I plan on using the datepicker with, however the code currently hangs up on the script references, as to my knowlege it looks ok, and I can't seem to find anything wrong with it: Code: <html> <head> <script> function open_cal() { var str_html = "" + "<!DOCTYPE html>" + "<html lang='en'>" + "<head>" + "<meta charset='utf-8'>" + "<title>CALENDAR</title>" + "<link href=jq/jquery-ui.css rel=stylesheet type=text/css/>" + "<script src=jq/jquery.min.js type=text/javascript></script>" + "<script src=jq/jquery-ui.min.js type=text/javascript></script>" + "</head>" + "<body>" + "<p>Hello test</p>" + "</body>" + "</html>" var j = window.open("","CALENDAR","width=200,height=250,status=no,resizable=yes,top=200,left=200") j.document.write(str_html); j.document.close(); } </script> </head> <body> <input onclick="open_cal()" type="button" value="Open" name="B1"> </body> </html> I need your help. Any ideas? Thanks very much in advance, J 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? 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 = "" ; } |