Connecting Tech Pros Worldwide Forums | Help | Site Map

newby trying to write text to a <div>

charliefortune
Guest
 
Posts: n/a
#1: Feb 9 '06
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.


Evertjan.
Guest
 
Posts: n/a
#2: Feb 9 '06

re: newby trying to write text to a <div>


charliefortune wrote on 09 feb 2006 in comp.lang.javascript:
[color=blue]
> 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">[/color]

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

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;
[color=blue]
> }
> </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.
>
>[/color]



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
charliefortune
Guest
 
Posts: n/a
#3: Feb 9 '06

re: newby trying to write text to a <div>


spot on, thank you v much.

Closed Thread