newby trying to write text to a <div>

C

charliefortune

I have succesfully made rollover images appear in a table cell, but I
cannot seem to make the caption appear in a seperate cell underneath.
This is how I attempted it ..

<script language="JavaScript" type="text/JavaScript">

function design(file, displayName){
viewer.src = 'assets/shirts/medium/'+ file +'.gif';
document.underText.write(displayName);
}
</script>
........
....
..
<td><div name = "underText" id = "underText"></div></td>
.......
......


The variables are being passed correctly as viewer.src works correctly.
The script appears before the <html> tag, but it doesn't seem to work
wherever I put it.
 
E

Evertjan.

charliefortune wrote on 09 feb 2006 in comp.lang.javascript:
I have succesfully made rollover images appear in a table cell, but I
cannot seem to make the caption appear in a seperate cell underneath.
This is how I attempted it ..

<script language="JavaScript" type="text/JavaScript">

Do not use language="JavaScript", unnecessary since abt. 2000
function design(file, displayName){
viewer.src = 'assets/shirts/medium/'+ file +'.gif';
document.underText.write(displayName);

You cannot use document.underText unless it is IE-only.
You cannot use .write like that anyway.
You cannot even use document.write after the page is ready,
and the DOM made, because an default documnet.open will be assumed and
that will destroy the previous HTML, DOM and the script itself!!!

So use the DOM to write to a div:

document.getElementById('underText').innerHTML = displayName;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top