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.
|
|
|
|
|
![]() |
||
Shorten Length of Database Text Displayed?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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... |
|
|
|
|||
|
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.
|
|
|||
|
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> |
![]() |
| Tags |
| shorten, length |
| Thread Tools | |
|
|
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 |