Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: text highlight

  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question text highlight

    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>

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this?
    Code:
    <!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>

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    wow

    that is perfect.
    Thanks beetle

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem. Glad it works for ya

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes! Isn't it wonderful! Gecko = kick a**


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •