SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    send onclick value to textarea

    Code:
    <input type="button" value="category" style="background-color:#ffffff;"
    										onclick="(form.f_query.value = '{CATEGORY}')">
    <input type="button" value="url" style="background-color:#ffffff;"
    										onclick="(form.f_query.value = '{URL}')">
    I want to do something similar to this, but instead of using buttons I want to use hyperlinks and I want to be able to click more than one hyperlink and have the textarea display all the clicked values.

  2. #2
    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)
    Here's one way to do it. Keep in mind that those 'A' elements will cause a page reload if Javascript is disabled.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>demo</title>
    <script type='text/javascript'>
    
    window.onload = btnsInit;
    
    function btnsInit()
    {
      var i, a = document.getElementById('btns').getElementsByTagName('a');
      for (i = 0; i < a.length; ++i) {
        a[i].onclick = btnClick;
      }
    }
    function btnClick()
    {
      document.getElementById('ta').value += '{' + this.firstChild.nodeValue + '}\n';
      return false;
    }
    </script>
    </head>
    <body>
    
    <div id='btns'>
    <p><a href=''>category</a></p>
    <p><a href=''>url</a></p>
    </div>
    
    <textarea id='ta' rows='10' cols='20'></textarea>
    
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works great in IE, but not in firefox.
    Any suggestions to get this to work in firefox?

  4. #4
    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)
    Works for me in FF 2.0

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just got a page reload in firefox. I am using version 1.5.0.9

  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)
    Try this
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>demo</title>
    <script type='text/javascript'>
    
    window.onload = btnsInit;
    
    function btnsInit()
    {
      var i, a = document.getElementById('btns').getElementsByTagName('a');
      for (i = 0; i < a.length; ++i) {
        a[i].onclick = btnClick;
      }
    }
    function btnClick(e)
    {
      document.getElementById('ta').value += '{' + this.firstChild.nodeValue + '}\n';
      xPreventDefault(e);
      return false;
    }
    function xPreventDefault(e)
    {
      if (e && e.preventDefault) e.preventDefault();
      else if (window.event) window.event.returnValue = false;
    }
    </script>
    </head>
    <body>
    
    <div id='btns'>
    <p><a href=''>category</a></p>
    <p><a href=''>url</a></p>
    </div>
    
    <textarea id='ta' rows='10' cols='20'></textarea>
    
    </body>
    </html>


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
  •