View Full Version : How do you write to a table cell?
Mhtml
10-06-2002, 05:34 AM
I can't seem to figure out how to write my variables to a table cell.
I can easily do it with a form element by using the .value = '' method but I'd like to be able to do it in a table cell because at the moment my form element is a <textarea> an I have used css to get rid of the scrollbars, well actually I just changed the colors to the same as the background and I don't like how that will degrade, as you will see that it is a <textarea>
chrismiceli
10-06-2002, 06:01 AM
is this what you are trying to do
document.tablename.trname.write(variable)
if not let me know
Mhtml
10-06-2002, 11:19 AM
That seems to be what I'm trying to do. But I can't seem to make it work.
I can make it write to a page but it just gets rid of the rest of the content and leaves the contents of the variablee on the page.
I tried to do it this way:
<script language="javascript">
function showthis(this){
document.displaycell.write(this)
}
</script>
<a href="#" onMouseOver="showthis('Test string')" onMouseOut="showthis('')">Test Link</a>
<table>
<tr>
<td name="displaycell"></td>
</tr>
</table>
I don't understand why it is not working, this is my first attempt at jacascript so I'm not real good yet.
chrismiceli
10-06-2002, 03:13 PM
try this,i edited this after messing with it, I forgot that you can not use this as a variable name, this is a reserved word in javascript.
<script language="javascript">
function showthis(test){
document.test.displaycell.write(test)
}
</script>
<a href="#" onMouseOver="showthis('Test string')" onMouseOut="showthis('')">Test Link</a>
<table name="test">
<tr>
<td name="displaycell"></td>
</tr>
</table>
the code still doesn't work but that is because i am not getting the path right eg. document.table1.tdname.write(), they say that it is null or not an object, meaning that that is not right. mabey someone else could help you out there, i know the test variable works because if you put this in the function it works alert(test), but alert(this) doesn't.
Graeme Hackston
10-06-2002, 04:03 PM
I don't remember where I got this from but I think it's what you're after
<html>
<head>
<title>Write HTML TO Layer</title>
<script language="JavaScript">
<!--
function writetoLyr(id, message) {
if (document.layers) {
document.layers[id].document.write(message)
document.layers[id].document.close()
} else if (document.all) {
eval("document.all."+id+".innerHTML='"+message+"'")
} else {
document.getElementById(id).innerHTML = message;
}
}
//-->
</script>
</head>
<body>
<div id="testLayer" style="position:absolute; width:200px; height:115px;
z-index:1; left: 99px; top: 160px"></div>
<a href="javascript:" onClick="writetoLyr('testLayer','Test it')">Click Me</a>
</body>
</html>
<edit>You'll have to remove the space between "java" and "script"</edit>
Garadon
10-06-2002, 04:10 PM
try this:
<script language="javascript">
function showthis(test){
document.getElementById("displaycell").innerText=test;
}
</script>
<a href="#" onMouseOver="showthis('Test string')" onMouseOut="showthis('')">Test Link</a>
<table>
<tr>
<td id="displaycell"></td>
</tr>
</table>
glenngv
10-07-2002, 02:12 AM
use innerHTML
document.getElementById("displaycell").innerHTML=test;
innerText doesn't work with NS6
chrismiceli, where did you learn this?
document.tablename.trname.write(variable)
joh6nn
10-07-2002, 02:32 AM
innerHTML does work with Gecko browsers, but it shouldn't. unfortunately, last i knew, IE doesn't have adequate support for the DOM methods, so innerHTML is the only thing you can use.
Mhtml
10-07-2002, 03:40 AM
Ok I am good at learning by example, so I get exactly how this works but I have a question, is innerHTML case sensitive?
It works fine in IE6.0 as innerText and innerHTML , is innerHTML cross browser? Is this what you were saying joh6nn?
glenngv
10-07-2002, 03:45 AM
javascript is case-sensitive, so all properties and methods of an object are.
Mhtml
10-07-2002, 04:17 AM
okey dokey, wasn't sure.
Thanks Peeps!:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.