|
| |
|
|
Ro
Posts: 60 Joined: 12/14/2004 From: Auckland's North Shore, New Zealand Status: offline
|
Truncate and More... Option - 1/9/2008 18:31:30
Hi everyone Happy New Year - this is my first post for the year - yippeeee I've got a DRW (with a diet) that has a memo field which I'd like to Truncate then have a "[More...]" link after 30 characters. You then click on the More and the rest of the info from the field pops up. I've found some js code which works in the first row but it's not working on the remaining rows of the table. This is the js code. /* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Patrick Fitzgerald | http://www.barelyfitz.com/ */
function truncate() {
var len = 30;
var p = document.getElementById('truncateMe');
if (p) {
var trunc = p.innerHTML;
if (trunc.length > len) {
/* Truncate the content of the P, then go back to the end of the
previous word to ensure that we don't truncate in the middle of
a word */
trunc = trunc.substring(0, len);
trunc = trunc.replace(/\w+$/, '');
/* Add an ellipses to the end and make it a link that expands
the paragraph back to its original size */
trunc += '<a href="#" ' +
'onclick="this.parentNode.innerHTML=' +
'unescape(\''+escape(p.innerHTML)+'\');return false;">' +
'<span style="font-size: 10px;">[ more ... ]</span><\/a>';
p.innerHTML = trunc;
}
}
}
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
truncate();
});
This is what goes in the HEAD <script type="text/javascript" src="truncateText.js"></script>
This is the BODY <p id="truncateMe">
Now I've put the BODY code here.... <td>
<p id="truncateMe">
<%=FP_FieldVal(fp_rs,"issues")%></td>
<td>
Is there anything I've forgotten? Have I put the truncateMe code in the wrong place? I'd appreciate your help Thanks heaps. Ro
|
|
|
|
Ro
Posts: 60 Joined: 12/14/2004 From: Auckland's North Shore, New Zealand Status: offline
|
RE: Truncate and More... Option - 1/10/2008 17:12:28
Thanks Spooky Yup that gave me the right idea... Now what did I do.... I made up a unique ID by adding ProjectID to ‘truncateMe’ and I also added a parameter (id) to the truncate function in truncateText.js. <p id="truncateMe<%=FP_FieldURL(fp_rs,"projectID")%>">
Then after each table row I added some javascript code that calls addLoadEvent function and adds truncate(currentid) calls to the onload event. </tr>
<script language="javascript">
//truncate('<%=FP_FieldURL(fp_rs,"projectID")%>');
addLoadEvent(
function() {
truncate('<%=FP_FieldURL(fp_rs,"projectID")%>');
}
);
</script>
<!--#include file="../_fpclass/fpdbrgn2.inc"-->
I hope this makes sense... it works a treat. Customer is happy :-)
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|