JavaScript, mulit-line document.write
I know that document.write(""); only takes one line of characters inthe quotes. Is there a way in javascript to open a "block" tag?
instead of having several document.write() lines,
have an opening document.write()
a bunch of lines of, say html
then a closing document.write()
I know that in Perl, for example, you can do this.
Let me know if I'm not explaining myself clearly.
Suzanne posted this at 20:36 — 20th February 2004.
She has: 5,507 posts
Joined: Feb 2000
Not that I know of. If you need to write that much, perhaps it would be better to use something other than JavaScript to do it?
cat_mother_ posted this at 20:46 — 20th February 2004.
They have: 20 posts
Joined: Jan 2004
The reason that I have to do it this way is a long story -- definitly not my choice of methods.
Thanks, though!
druagord posted this at 20:57 — 20th February 2004.
He has: 335 posts
Joined: May 2003
by putting "\n" in your string it will give you a line return in source code. no there is no way in javascript to duplicate perl behavior. usualy i do it like this
<script>
myvar = "<div>this is line 1 of some test text\n";
myvar+="this is still line 2</div>";
document.write(myvar);
</script>
IF , ELSE , WHILE isn't that what life is all about
cat_mother_ posted this at 21:14 — 20th February 2004.
They have: 20 posts
Joined: Jan 2004
I'm asking if there's a way to include multiple lines of code inside document.write(). For example, say I have an html page. The coding of the html page is about 50 lines of code. I want all of this code inside the document.write() methods, whichout having to write document.write() 50 times.
Seems like there isn't a way to do that, but I thought that I'd ask!
druagord posted this at 21:28 — 20th February 2004.
He has: 335 posts
Joined: May 2003
like i said you can but it will be on a terribly long line and it is not a good coding practice that's why i set a variable with all the text in it and write it after you could also read it from a text file and then write it to the document
IF , ELSE , WHILE isn't that what life is all about
cat_mother_ posted this at 21:38 — 20th February 2004.
They have: 20 posts
Joined: Jan 2004
thanks for the info.
I'll give that a try.
Abhishek Reddy posted this at 22:14 — 20th February 2004.
He has: 3,348 posts
Joined: Jul 2001
A tricky way to do it would be to store your code in another page element and access it via DOM. Perhaps use a hidden textarea (CSS) to contain your code block, and use document.getElementById("myhiddentextarea").value to grab the block. I am assuming, of course, that your Javascript code is embedded in your page. And this is untested, but may be worth a shot if you have no alternatives.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.