SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question hyperlink into textarea

    I have a textarea that gets populates when users click on hyperlinks.

    What I'm trying to do via one of the links is insert a mailto: hyperlink, but I can't get it to work:

    here's my .js code:

    document.getElementById('servicestext').value = "Click the sales link here
    '<a href="' + mailto:sales@sales.com + '">' + sales@sales.com + '</a>' to help us help you!";

    The error I get back is object expected which points to the html page containing the hyperlink, not to the .js file.

  2. #2
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a textarea that gets populates when users click on hyperlinks.
    Like this?
    Code:
    function get(el) {
      return document.getElementById(el);
    }
    get('my-link').onclick = function() {
      get('my-textarea').value = 'hello world';
    }

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2007
    Posts
    472
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try like this
    <script>
    function xx(){
    document.getElementById('servicestext').value = "Click the sales link here<a href=\"mailto:sales@sales.com\">sales@sales.com</a> to help us help you!";
    }
    </script>
    <textarea name="servicestext" onclick="javascriptx()">
    </textarea>

  4. #4
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah. in that case, also escape the html entities. Instead of '<', write &lt; - and for '>' write &gt;

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi All!

    Thanks for the suggestions!

    Whatever I use to escape the characters or entities, that exact text gets written to the textarea. The anchor doesn't turn into a link.
    Should I just use a <DIV> instead?


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
  •