PDA

View Full Version : Trouble using list tags in document.write


CdnBacon
09-08-2002, 07:11 PM
I am brand spankin new to JavaScript!!!

Although it seems cool, I am already having trouble...

For an assignment, our teacher is asking us to simply take a couple of paragraphs that he wrote and display them the same way but using only document.write.

Question 1: Is it proper to make each paragraph its own document.write or put all the paragraphs into one?

Question 2: This is the only one that doesn't seem to be working... no error, but won't show in browser...

<script language="JAVASCRIPT" type="TEXT/JAVASCRIPT">
document.write("<ul>
<li />Arithmetic: evaluates to a number, for example 3.14159
<li />String: evaluates to a character string, for example, \"Fred\" or \"234\"
<li />Logical: evaluates to true or false
</ul>
<p />");
</script>

Thanks,
CdnBacon

Quiet Storm
09-08-2002, 08:33 PM
Cut-n-paste this:


<SCRIPT LANGUAGE="JavaScript">
document.write('<UL><li />Arithmetic: evaluates to a number, for example 3.14159<li />String: evaluates to a character string, for example, "Fred" or "234"<li />Logical: evaluates to true or false <p /></UL>')
</SCRIPT>

CdnBacon
09-08-2002, 08:38 PM
Thanks so much!

So explain to me what was going wrong...

And about my first question, is it proper javascript form to use a diff document.write for each paragraph or lump it all tother?

umm
09-08-2002, 09:01 PM
I think it depends on what you want to do. Personally, I tend to use seperate document.write statements because for me it improves readability.

Also, you can use a variable like so:

function testMe(){
var msg=""
msg+="<html>"
msg+="<head><title>Test</title></head>"
msg+="<body><h1>Hello World</h1></body>"
msg+="</html>"

document.write(msg)

}

In the end, it's a matter of preference I guess.

Quiet Storm
09-08-2002, 09:03 PM
I don't know what the problem was...

I kept getting an error on"line 5", so I ended up rewriting it from the beginning - now it works. I don't know why. :)

I usually write entire lines inside the document.write with no problems - but there is a point where you'll need to seperate lines, not sure when/where, but there is a point. :)

CdnBacon
09-08-2002, 09:13 PM
I noticed you put my </ul> tag AFTER the end of the paragraph... I will try that right now.

I appreciate your help with this... I can tell you right now, that I will be back more than once :)