in*****@rcn.com wrote:
I thinks its a table issue, not something inherent in the javascript
code, but here goes:
Please quote what you are replying to. Your problem has nothing to do
with JavaScript, however improvement is always possible. :-)
function writeToDiv(div, str)
{
if(document.all) {
document.all(div).innerHTML=str;
} // IE4 NS5
else if(document.getElementById) {
document.getElementById(div).innerHTML=str;} // IE5 NS6
else if(document.layers) {
with (document.div.document)
{ open();
write(str); // NN4
close();
}
}
You should test for getElementById first, it is likely more widely
supported that document.all (or soon will be) so test for it first:
if(document.getElementById)
{
document.getElementById(div).innerHTML=str;
}
else if(document.all)
{
document.all(div).innerHTML=str;
}
else if(document.layers)
{
/...
Have a look at the group FAQ for a variety of ways to implement the above.
Table Row example (one option)
<tr>
<td width="30%">Name:</td>
<td width="70%"><input type="text" name="name" size="10" maxlength="10"
<div d="ename"> </div></td>
A div is a block level element and so will appear on a line by itself
unless you make it do something else. Use an inline element (say a
span) and you get the result you are after if you heed the following.
Your attempt at TD sizing fails (comp.infosystems.
www.authoring.html
will help there) so your new text is forced to wrap - percentages are
always messy. Fixed-size columns are bad, so use CSS and em or ex or
similar that will scale with the font size and you are happy again.
I think there was a brace missing from your script, and you have a
typo - there is no 'd' attribute for a div, I think you meant 'id'. ;-p
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Show random matrix</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
..nameCol { width: 6em; }
..entryCol { width: 20em; }
</style>
<script type="text/javascript">
function writeToDiv( div, str) {
if ( document.getElementById ) {
document.getElementById( div ).innerHTML=str;
} else if( document.all ) {
document.all[ div ].innerHTML=str;
} else if( document.layers ) {
with ( document.div.document ) {
open();
write(str); // NN4
close();
}
}
}
</script>
</head>
<body>
Table Row example (one option)
<table border="1">
<tr>
<td class="nameCol">Name:</td>
<td class="entryCol"><input type="text" name="input1"
size="10" maxlength="10" onchange="
writeToDiv( 'ename', this.value );
"><span id="ename"> </span></td>
</tr>
</table>
</body></html>
--
Rob