Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<textarea> help in ColdFusion

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
US
I am having text datatype column on my database. I am populating this column and display the bulk message into screen display. When i have 2000 words of message from a field, i wish to show 2 lines and for remaining i need to display them on a popup window thru a link.

E.g,

-----------------------

"This is a test message message message message message message message message message message message"
more...

------------------------

if i click the link "more..", i need to display a popup window with full message from the column.

Regards
micJ
 
sort of falconseye.

micjohnson, you cant just say 2 lines. you can specify a number of characters like falconseye did but his logic is a bit backwords. I'm also assuming 2000 is just a large number you spit out. This is common to do when you have limited room to show a huge amount of text

Code:
<!--- set the max number of chars to show in the preview --->
<cfset maxChars = 300>
<!--- check the len and make sure it's more than maxchars --->
<cfif len(myMsg) GT maxChars>
<!--- if it's longer than you want it to be show the first "maxChars" chars --->
  <cfoutput>#left(myMsg, maxChars)#... <a href....>more</a>
<cfelse>
<!--- if it's less than the max length just output the string --->
  <cfoutput>#myMsg#</cfoutput>
</cfif>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Here is one tweak to truthInSatire's code. Try to stop at the end of a sentence. And typically a sentance is a period followed by a space.

Change:
Code:
<cfoutput>#left(myMsg, maxChars)#... <a href....>more</a></cfoutput>

To:
Code:
<cfset endPos = find(". ",myMsg,maxChars-1)>
<cfif endPos NEQ 0>
   <cfoutput>#left(myMsg,endPos)#... <a href....>more</a></cfoutput>
<cfelse>
   <cfoutput>#left(myMsg, maxChars)#... <a href....>more</a></cfoutput>
</cfif>

I have not tested this but maybe you get the idea.

Kris Brixon

If you're not failing every now and again, it's a sign you're not doing anything very innovative.
- W. Allen
 
nice simple solution, Kris.

now that I see it I would go one further..

Code:
<cfoutput>#left(myMsg, maxChars)#... <a href....>more</a></cfoutput>

<cfset endPos = find(". ",myMsg,maxChars-1)>
<cfif endPos NEQ 0>
	<cfoutput>#left(myMsg,endPos)#... <a href....>more</a></cfoutput>
<cfelse>
	<cfset tmpList = left(myMsg, maxChars)>
	<!--- So you don't get half of a word, it cuts at a space. --->
	<cfoutput>#listDeleteAt(tmpList,ListLen(tmpList," ")," ")#... <a href....>more</a></cfoutput>
</cfif>

again, not tested... but you get it.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top