Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding HTML.

Status
Not open for further replies.

teky

Programmer
Mar 24, 2000
55
US
I am trying to output my result using the folowing HTML tags.

document.write(&quot;<font face=&quot;Arial,Helvetica&quot; size=&quot;2&quot; color=&quot;#00048&quot;>&quot;+&quot;<b>&quot;+currenthits+&quot;</b>&quot;+&quot;</font>&quot;)

But when I try to see the result in the browser, I get an
error message.

Can anybody please explain this.

Thanks
Teky.



 
what you need to do is stop putting &quot;'s in the string as this confuses the javascript interpreter as to what is part of the string and what isn't. use document.write like this...

document.write(&quot;<FONT face='Arial, Helvetica' size=2 color='#00048'><B>&quot; + currenthits + &quot;</B></FONT>&quot;);


Notice how I've only used &quot;'s twice. this then can be correctly interpreted by the javascript and HTML parser. Klae

You're only as good as your last answer!
 
Or you can escape the double quotes inside your HTML string:
Code:
document.write(&quot;<font face=\&quot;Arial,Helvetica\&quot; size=\&quot;2\&quot; color=\&quot;#00048\&quot;>&quot;+&quot;<b>&quot;+currenthits+&quot;</b>&quot;+&quot;</font>&quot;)

This is often a more traditional programmer's way to do it. Kale's method works just fine until you also happen to need an extra level of evaluation inside your string, for example if the HTML you are outputting just happens to have Javascript of it's own inside the HTML string, such as:

Code:
document.write(&quot;<a href=\&quot;otherpage.html\&quot; onmouseover=\&quot;alert('Leaving Current Page')\&quot;><font face=\&quot;Arial,Helvetica\&quot; size=\&quot;2\&quot; color=\&quot;#00048\&quot;>&quot;+&quot;<b>&quot;+currenthits+&quot;</b>&quot;+&quot;</font></a>&quot;)

This method leaves you with another level &quot;on reserve&quot; with single quotes, since otherwise the text inside the alert() statement would try to evaluate right away, instead of waiting for onmouseover.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top