Shorten Length of Database Text Displayed?

This is a discussion on "Shorten Length of Database Text Displayed?" within the JavaScript Forum section. This forum, and the thread "Shorten Length of Database Text Displayed? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 10th, 2006, 16:11
New Member
Join Date: Aug 2006
Location: Tucson, AZ
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Shorten Length of Database Text Displayed?

Here's my situation. I have a database set up and I need to display the information on a page. One of the fields can be rather lengthy. I want to set up a javascript function to shorten the length of the text that is displayed to no more than 25 characters of that field, not the actual length of the data that can be in the database. Here is the script that I have been messing around with. Any thoughts or help are greatly appreciated. Thanks - Richard

<script language="javascript">
function shorten(sString, sLength) {
if Len (sString) > sLength {
shorten = left(sString,sLength) & "...";
} else {
shorten = sString
}
}

function sOrg() {
sOrg = <%=(recordset1.Fields.Item("data").Value)%>
sOrg = shorten(sOrg,25)
}
sOrg()
document.write (sOrg)
</script>

Example of how I would like it to display if the length is more than 25 characters:
This database field has e...
Reply With Quote

  #2 (permalink)  
Old Oct 10th, 2006, 22:52
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Shorten Length of Database Text Displayed?

JavaScript doesn't have a 'left' function. You need to use 'substring()'. Also '&' isn't used to join two strings. Further note that the string being examined is zero based.
Code: Select all
shorten = sString.substr(0, 24) + '...';
Reply With Quote
  #3 (permalink)  
Old Oct 11th, 2006, 15:38
New Member
Join Date: Aug 2006
Location: Tucson, AZ
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Shorten Length of Database Text Displayed?

Thank you, Geoff. It appears that I was mixing up my javascript with vbscript. I reworked it a bit more, but you definitely pointed me in the right direction. Here's the script I have working.

<script language="javascript">
function sOrg() {
sOrg = "<%=(recordset1.Fields.Item("data").Value)%>";
if ((sOrg.length) > 24) {
sOrg = sOrg.substr(0,24) + "...";
} else {
sOrg = sOrg;
}
document.write (sOrg)
}
sOrg()
</script>
Reply With Quote
Reply

Tags
shorten, length

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
href.to - shorten any url plusminus Free Web Site Critique 5 Sep 25th, 2007 19:27
3 column div layout, not same length tox0tes Web Page Design 8 Jun 28th, 2007 15:08
This is sooo taxing! Can I shorten? JustinStudios PHP Forum 5 Apr 26th, 2007 03:05
setting page length wmw Web Page Design 6 May 22nd, 2006 16:17
Retrieving text from database and writing back as url wheatus Classic ASP 5 Dec 22nd, 2004 11:36


All times are GMT. The time now is 19:36.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43