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?


<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>

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


<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>