www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] textarea truncate to fit width

  1. #1
    Join Date
    Dec 2010
    Posts
    232

    resolved [RESOLVED] textarea truncate to fit width

    In my site I have an area where users can send messages to other users that has the username of the person they are sending it too automatically entered into the textarea used for the messages followed by a space and a dash and then another space and then I want the user to be able to enter their message after that so it appears something like this:-

    username - users message goes here bllah blah blah blah blah

    What I want though is for the message to be truncated in a certain way. The problem I have is this if the user enters the following:-

    username -
    wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

    The 'w's go onto a whole new line once they exceed the width of the text area whereas I want it to actually do this:-

    username - wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
    wwwwwwwwwwwww

    Similar to the way twitter truncates their entries, if truncate is the right word for it.

    How can this be done?

  2. #2
    Join Date
    Apr 2011
    Posts
    13
    try this:
    PHP Code:
    echo wordwrap($longword80"\n"TRUE); 
    http://www.webdeveloper.com/forum/sh...d.php?t=163466

  3. #3
    Join Date
    Dec 2010
    Posts
    232
    Hi Rahim. Thanks for the reply. That looks good but I need it to work on the fly i.e. as the user is actually entering text. Will that work as the user is entering text into a textarea?

  4. #4
    Join Date
    Apr 2011
    Posts
    13
    oops. wrong place.

  5. #5
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    Quote Originally Posted by jimmyoneshot View Post
    That looks good but I need it to work on the fly i.e. as the user is actually entering text. Will that work as the user is entering text into a textarea?
    In short, no it wont. The text field is tried to the browser (actually more to the the operating system than the browser), so it's going to behave the way the OS works.

    There might be a way to "listen" to the inputs with javascript, and add a 'newline' character in certain places.

  6. #6
    Join Date
    Dec 2010
    Posts
    232
    Thanks october wind. I know what you mean now. After looking more closely it seems that Twitter also does it the way I posted above i.e. the www... would go onto a new line rather than truncating.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles