|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Confusing If Statement
I'm trying to create an if statement that will limit the amount of characters that are displayed from the document.write command. This is what i'm trying to get to happen. I need it so that if the text is over 500 characters long, the last 14 characters will be replaced with "...(hyperlink)"
|
|
#2
|
||||
|
||||
|
Code:
max_length = 500;
extra_text = "...(hyperlink)";
function trunc_text(str) {
if( str.length > max_length) {
str = str.substring(0, (max_length - extra_text.length)) + extra_text;
}
return str;
}
document.write(trunc_text("here are some words"));
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
Quote:
Thanks, this code works perfect |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Confusing If Statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|