...

View Full Version : text highlight



wolf
08-06-2002, 03:09 PM
Can someone help me with highlighting all the text in a table cell?

I am currenly using this to create a printer friendly display of the text output. (This is the short version. There are multiple strings over many lines).

I could use a textarea, but the scroll bar prevents everything from being displayed (not printer friendly). Is there another way to do this?

function Display()
{
str = "This is an example of the text output";
document.all['previewDisplay'].innerText = str;
// add select all here
}

...

<form name="previewform">
<TABLE>
<TR><TD ID = "previewDisplay">
</TD></TR>
<TR><TD><INPUT type = "button" value = "Finished" onclick = Display()></TD></TR>
</TABLE>
</form>

beetle
08-06-2002, 03:43 PM
Something like this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN" />
<HTML>
<HEAD>
<TITLE>Blah</TITLE>
<META NAME="Generator" CONTENT="TextPad 4.4" />
<META NAME="Author" CONTENT="Peter Bailey" />
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript" />
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css" />

<script>

function selectTD(cell)
{
if (cell.tagName == 'TD')
{
var tr = document.body.createTextRange();
tr.findText(cell.innerText);
tr.select();
}
}

</script>

<style>
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #FFFFFF; color: #000000; }
table.clickable td {
cursor: hand;
}
</style>

</HEAD>

<BODY>
<table border="1" cellpadding="4" cellspacing="3" class="clickable" onClick="selectTD(event.srcElement)">
<tr>
<th>asd web</th><th>werbw tmrt</th><th>u.yuk ethj</th>
</tr>
<tr>
<td>2346 1347</td><td>6934 61236</td><td>1233445 7569</td>
</tr>
<tr>
<td>!@#% $%*@</td><td>(*(&!#%!#</td><td>":@^!" @#%</td>
</tr>
<tr>
<td>POUIQ OERI[PIM</td><td>ASDV;AS DOUIN</td><td>IPEO QWINHF</td>
</tr>
</table>
<script type="text/javascript">

</script>

</BODY>
</HTML>

wolf
08-06-2002, 04:27 PM
that is perfect.
Thanks beetle

beetle
08-06-2002, 04:41 PM
No problem. Glad it works for ya

jkd
08-06-2002, 07:17 PM
Just to envangelize Gecko browsers (NS6+, Mozilla, etc):

HTMLElement.prototype.selectText = function() {
var range = this.ownerDocument.createRange();
range.selectNodeContents(this);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
range.detach();
}

Now, refToTDCell.selectText() will highlight the text. :)

beetle
08-06-2002, 07:22 PM
Yes! Isn't it wonderful! Gecko = kick a** :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum