navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Truncate and More... Option

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Truncate and More... Option
Page: [1]
 
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
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Truncate and More... Option - 1/10/2008 13:36:13   
HNY!
You should also have a closing tag on the ID, however Im assuming each one would need a uniqueID so it knew which one it was expanding?
I normally do that sort of thing in asp and post to a new page - however, it would be cleaner if you can do it with innerhtml

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to 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 :-)

(in reply to Spooky)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Truncate and More... Option - 1/10/2008 17:18:27   
Yep, nice!

You can leave this line out - its just a comment

//truncate('<%=FP_FieldURL(fp_rs,"projectID")%>');

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to Ro)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Truncate and More... Option
Page: [1]
Jump to: 1





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