PDA

View Full Version : Simple JavaScript?


bman
10-12-2004, 08:17 AM
I'm using this simple and short js script on a page of my web site, but am unable to use an apostrophe (') in the text. I've tried both \ and \n, but neither work. Any suggestions?

<script language="JavaScript1.2">

function writetoLyr(name, message) {
if (document.layers) {
document.layers[name].document.close();
document.layers[name].document.write(message);
document.layers[name].document.close();
} else {
if (document.all) {
eval("document.all." + name + ".innerHTML='" + message + "'");
} else {
document.getElementById(name).innerHTML = message;
}
}
}
</script>

text to display:

<a href="javascript:;" onMouseOver="writetoLyr('pageLayer', '<P>text would display here</P>')">link goes here</a>

text displayed in a DIV:

<DIV id="pageLayer"></DIV>

As always, being severaly js-challenged, I appreciate your help!

Barry

n8thegreat
10-12-2004, 08:39 AM
message = "<a href=\"javascript:;\" onMouseOver=\"writetoLyr('pageLayer', '<P>text would display here</P>')\">link goes here</a>";

you have to escape the double quotes, not the single quotes
also, change:
eval("document.all." + name + ".innerHTML='" + message + "'");

to

document.all[name].innerHTML = message;



its best not to use eval()

bman
10-12-2004, 08:53 AM
Thanks Nate, for a quick response with the solution! It works fine now.