Click to See Complete Forum and Search --> : Using JS to generate HTML


web-eagle
04-26-2003, 03:22 PM
..…and he trepidatiously approaches the microphone…..
.....testing...one...two...hello?...testing.....

This is just a test for something I want to try later, but I can’t figure out why it isn’t working. All the HTML tags I use work fine with this “system”, but not the images. Here’s a sample.

var lnk = "www.tld.com"
var img = "tld.gif"
document.write("<a href=& q u o t ;" + lnk + "& q u o t ;><img src=& q u o t ;" + img + "& q u o t ;></a>")

This produces a blue border around a working link, but no image (just the little red “x”). The image does exist, and everything is in the same directory. As a test, I wrote the following in straight HTML

<a href="www.tld.com"><img src="tld.gif"></a >

and it works fine.

What am I missing???

---
Note: In the above code, I've spaced out "& q u o t ;", so the forum won't display it as a " sign. In my page, it's done correctly.

AdamGundry
04-26-2003, 03:31 PM
You need to use normal double quotes, and escape them, like this:

document.write("<a href=\"" + lnk + "\"><img src=\"" + img + "\"></a>");

Alternatively, use single quotes for the outside quotes:

document.write('<a href="' + lnk + '"><img src="' + img + '"></a>');

Adam

web-eagle
04-26-2003, 04:17 PM
Both methods worked beautifully!
Thanks, Adam