SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Mo Money's Avatar
    Join Date
    Nov 2002
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Click a link which adds text to a textarea?? please help!

    Hello,

    I need to know how to have multiple links on a page and when you click on each one it populates a text box. Do you understand what im saying? Basically I want a bunch of links on one side of the page, and on the other a textarea. Then if you click one of the links like oranges text will pop up in the textarea "Oranges are well orange (haha) and have a very sweet taste". you know? Thank you!
    AbcArcade.com - free internet games!

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    function AddText(txt)
    {
    document.form_name.field_name.value=txt
    }

    <A HREF="#" onClick="AddText('Oranges are orange!')">Oranges</A>
    <A HREF="#" onClick="AddText('Apples can be green')">Apples</A>

    If you want to add the text to the textarea each time a link is clicked on then change your function to this:

    function AddText(txt)
    {
    document.form_name.field_name.value+=txt
    }

  3. #3
    SitePoint Addict Mo Money's Avatar
    Join Date
    Nov 2002
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres my code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="Javascript">
    function AddText(txt)
    {
    document.form_name.field_name.value+=txt
    } 
    </script>
    </head>
    
    <body bgcolor="#cccccc">
    
    <A HREF="#" onClick="AddText('Apples can be green')">Apples</A><br>
    <textarea cols="40" rows="15"></textarea>
    
    
    </body>
    </html>
    It isnt working, does anyone know what the problem is?
    P.S -> Thank you requestcode
    AbcArcade.com - free internet games!

  4. #4
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to put a <form> tag around your <textarea> tags and a name to the <textarea>. Then rename the form_name and field_name in the javascript function.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
    <head>
    <title>untitled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="Javascript"> function AddText(txt) { document.form_name.field_name.value+=txt } </script>
    </head>
    <body bgcolor="#cccccc">
    <A HREF="#" onClick="AddText('Apples can be green')">Apples</A>
    <br>
    <form name="form_name">
    <textarea cols="40" rows="15" name="field_name"></textarea>
    </form>
    </body>
    </html>

    Just change it to what you want.


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
  •