Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts

    how to change the length of a string

    i have a xml file where i do the following query:

    Code:
    entry_03_title=doc.documentElement.getElementsByTagName("entry")[2].getElementsByTagName("title")[0].firstChild.data;
    now having the variable "entry_03_title" i would like that javascript do this:

    Code:
    if(entry_03_title.length>30)    entry_03_title.length=6
    in other words if the title is bigger than 30 chars long make it 6 chars, but this doesn't work.any thoughts?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,537
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    if(entry_03_title.length > 30) entry_03_title = entry_03_title.substring(0,6);

    Maybe time to download a JavaScript reference manual? There are a few good ones out there.


  •  

    Posting Permissions

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