Gossamer Forum
Home : Products : DBMan : Customization :

Need to shorten description field for short display...

Quote Reply
Need to shorten description field for short display...
Can someone tell me how I can shorten the description field to a set number of characters or words only for my short display. The user fills out a description field when they add a record, but it can be very long and I dont want all that length to show up on my short display, so instead I would like it to cut off and either have a "click here to view more" or just the "..." after so many characters or words. Im not sure how to go about this. Thanks! Smile
Quote Reply
Re: [wdu2002] Need to shorten description field for short display... In reply to
$shortdesc = $rec{'description'};

substr($shortdesc, 10) = "...";

then use
print $shortdesc;

to print the first ten characters plus three trailing dots.

(from page 133 of "Perl for Dummies" - took me a minute to figure it out Smile - highly recommend the book)
Quote Reply
Re: [Watts] Need to shorten description field for short display... In reply to
Thanks Watts, it works somewhat! When I leave the value at 10, it works just fine, but 10 characters isnt enough so when I try to change the number to anything else, I get the Fatal error that says Modification of a read only value. Would you know why it does this? I dont see anywhere it specifies the length as read only?!?

BTW, thanks for the heads up on that book. I'll look for that. Smile


Edit, I also just noticed that even when the value is at 10, it works fine on the first page of my results, but any other pages (if I click on page 2 of results for example) I get the same modification of read only value error. ????

Last edited by:

wdu2002: Jun 28, 2002, 1:01 PM
Quote Reply
Re: [wdu2002] Need to shorten description field for short display... In reply to
>>substr($shortdesc, 10) = "..."; <<

Try:

$shortdesc = substr($shortdesc, 0, 10) . "...";
Quote Reply
Re: [wdu2002] Need to shorten description field for short display... In reply to
Don't have a clue about the error message... I tried it by typing it in active perl, but did not try it with multiple records, which is probably the cause of the error.

Make the change suggested by Paul and see what happens.

Good Luck...

If it comes down to it, you can create a separate hidden field in the db that would keep a "short version" of the description by using javascript like this:
Code:
<SCRIPT LANGUAGE="JavaScript">
function shortDesc() {
document.form.ShortDescription.value = document.form.LongDescription.value;
}
</SCRIPT>

<INPUT TYPE="hidden" NAME="ShortDescription" VALUE="$rec{'ShortDescription'}" MAXLENGTH="50">

<INPUT TYPE="text" NAME="LongDescription" VALUE="$rec{'LongDescription'}" SIZE="35" MAXLENGTH="200" onChange="shortDesc()">
The only caveats, are:
1. Can you set "maxlength" in a hidden field? (don't do it in default.cfg or it'll throw out an error)
2. If you use the onChange event handler it may not set the value of the hidden field if the 'long' field is empty. You may have to use onKeyUp or something instead of onChange.
3. If maxlength on the 'short' field is set to less than that of the 'long' field will it cause a javascript error.

Anyway... good luck and I hope at least something works!

Last edited by:

Watts: Jun 28, 2002, 2:43 PM
Quote Reply
Re: [Paul] Need to shorten description field for short display... In reply to
Thanks Paul, works perfectly now! Wink
Quote Reply
Re: [wdu2002] Need to shorten description field for short display... In reply to
Cool... ignore my post above then. PW to the rescue!