SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting <br /> (enter) into textarea

    I'm trying to click a link and insert some text into a textarea. I can do this by
    Code:
    document.getElementById("comment").value = insertedtext;
    But I want to insert it like when you hit the enter key, so there is the return spaces in it. I tried using <br> but that shows up since it is viewed as a string. I tried using .innerHTML instead of .value and that didn't work, least it didn't in Firefox. There a way to do this? If not I'll have to turn it into [br] and change it to <br> after submission.
    Half way to nowhere

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.getElementById("comment").value = "First line\nSecond line";
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Addict
    Join Date
    May 2003
    Location
    sitepoint
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that worked just like I was hoping. Can't believe I didn't think of that! I know this is off topic, but instead of starting another thread. You know how to make the viewport/browser scroll to a id name? Like an anchor tag does, but instead with out needing to be clicked? I'm searching the forum though, if not. But thanks for helping me with the original question.
    Half way to nowhere

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can find the position of the element and use window.scrollTo().
    Birnam wood is come to Dunsinane


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
  •