SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    Lexington, KY
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limit external.php output?

    I've came across this code on the vbulletin forums probably a year or two ago and everything has been working great however I would like to change the output a bit. Right now the script will output the entire thread title on my home page (html page).

    What I'd like to know from any of your javascript programmers, is there a way to limit the thread title length? Say instead of the entire thread title maybe only show the first 15 characters?

    Code:
    <script type="text/javascript" src="http://www.domain.com/forum/external.php?type=js"></script>
            <script type="text/javascript">
            <!--
            for (x = 0; x < 8; x++)
            {
            document.writeln("<li><a href=\"http://www.domain.com/forum/showthread.php?t="+threads[x].threadid+"\" title=\""+threads[x].title+"\">"+threads[x].title+"</a></li>");
            }
            //-->
            </script>

  2. #2
    SitePoint Zealot xzyfer's Avatar
    Join Date
    Mar 2004
    Location
    oz
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the String.substr() function.
    You can learn more about it and other string manipulation functions here http://www.w3schools.com/jsref/jsref_obj_string.asp

    Code:
    <script type="text/javascript" src="http://www.domain.com/forum/external.php?type=js"></script>
            <script type="text/javascript">
            <!--
             var length_of_string = 15;
            for (x = 0; x < 8; x++)
            {
                      var title = threads[x].title.substr(0, length_of_string);
                      document.writeln("<li><a href=\"http://www.domain.com/forum/showthread.php?t="+threads[x].threadid+"\" title=\""+title+"\">"+title+"</a></li>");
            }
            //-->
            </script>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •