SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solved] textarea wrap hard and counting lines

    Happy new year to all

    Is there any way of counting, on the onkeyup event of a textarea, the number of lines ?
    I tried with a split, but the wrap doesn't seem to insert any char I could split on ??

    I though of transferring texte into a div and catching it's scrollHeight...

    I am running out of ideas
    Last edited by SpaceFrog; Jan 8, 2007 at 06:35.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you like to count the lines and not the amount of letters typed?

  3. #3
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    because I have to fit text in a fixed height container ...

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The textarea needs to have the same width as the element then. Just check that the textareas scrollHeight is not bigger than the containers height.

  5. #5
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yas that was what I wad thinking of when I was talking about scrollHeight, but I was actually willing to do this on the onkeyup event of the textarea before transferring to another container (not on same page)

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have two demos that are somewhat related. Perhaps they will give you some ideas: TA Autosize, TA AddRows

  7. #7
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TA Addrows it is really beautiful, I love it, thanks. I think this so simple and genial, that it should be standard part of comment textarea.

  8. #8
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mirek,

    Thank you very much! I too think it is a cool idea - and it doesn't take much Js to implement.

    Thanks again

  9. #9
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't like the setTimeout that much so in transferred the function pnto the onkeyup event ... and put a wrap hard on the textarea ...

    Thanks !

  10. #10
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great idea!



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
  •