Closed Thread Icon

Topic awaiting preservation: Is this doable in Javascript.... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24423" title="Pages that link to Topic awaiting preservation: Is this doable in Javascript.... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Is this doable in Javascript.... <span class="small">(Page 1 of 1)</span>\

 
Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 12-16-2004 22:02

I guess this is a bit of a challenge for some people

But, got a question to if something is dooable or not.

- I have a ASP.NET app which is spitting out tables, however I want each cell to have a fixed width, and if the content of the cell is too long, then the contents are cutoff and when you hover over the cell, a little tool-tip box pops up with the full content of the cell in it.

The only way I can think of doing this (which is how I am doing it now), is checking the length of the string in the cell, and if the string length > whatever, I'm doing

....pesdocode

code:
text = <a href=# title=text>text.mid(1,lenght).....</a>



However, depending on the users browser / reso / fontsizes / etc.... its still possible to get line-wraps.

is there a way of doing it that is not simply based on the character lenght of the cell contents?

... I got a feeling that is going above and beyond what you can do with javascript....

Nathus
Bipolar (III) Inmate

From: Minnesota
Insane since: Aug 2003

posted posted 12-17-2004 00:40

I threw something together using some CSS and javascript that I think does what you want. Only works in IE though at the moment. I'm not very good with javascript but I had an idea about this and it seemed to work.

The main drawback was that I couldn't get the table cells to stop wrapping lines so I put a div in each table cell that I set the height to 1em, width to that of the table cell and overflow:hidden. So its extra pretty useless code.

You can see an example here

I'm sure someone who actually knows javascript well could get it to work in other browsers than IE.

If you look at the first table cell in Firefox you can see that the method works in FF, but the script that goes through the table and ads that mouseover to each cell doesn't.

code:
<html>
<head>
<style type="text/css">
<!--
table {
width:500px;
}
td {
width:250px;
}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
//write styles to hide overflowed content only if javascript is on to be
//able to show it
document.write("<style type=\"text/css\">" +
"td div {" +
" width:250px; " +
" height:1em; " +
" overflow:hidden; " +
"}</style>");
var re = new RegExp ('</?div>', 'gi') ;
function startList() {
tableRoot = document.getElementById("table");
for (i=0; i<tableRoot.cells.length; i++) {
node = tableRoot.cells[i];
node.onmouseover=function() {
this.title = this.innerHTML.replace(re,'');
}
}
}
window.onload=startList;
//-->
</script>

</head>
<body>
<table id="table" width="500" border="1">
<tr>
<td onmouseover="this.title = this.innerHTML.replace(re,'');">
<div>This is a test, this is just a test. All it really is is a test</div></td>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
</tr>
<tr>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
</tr>
<tr>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
</tr>
<tr>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
<td><div>This is a test, this is just a test. All it really is is a test</div></td>
</tr>
</body>
</html>


**edit** Ok, I fixed it so it works in Firefox as well the javascript now is

code:
var re = new RegExp ('</?div>', 'gi') ;
function startList() {
tableRoot = document.getElementById("table");
for (i=0; i<tableRoot.rows.length; i++) {
for(j=0; j<tableRoot.rows[i].childNodes.length;j++) {
node = tableRoot.rows[i].childNodes[j];
node.onmouseover=function() {
this.title = this.innerHTML.replace(re,'');
}
}
}
}


Not sure how this works in opera or any Mac browsers
(Edited by Nathus on 12-17-2004 00:42)

(Edited by Nathus on 12-17-2004 00:54)

Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 12-17-2004 03:25

Ah, totatly didnt think about wraping it in a div like that, it will give me the effect I am after, exellent! thanks.

« BackwardsOnwards »

Show Forum Drop Down Menu