Results 1 to 3 of 3

Thread: Addtext to textfield on click

  1. #1
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Addtext to textfield on click

    Hope some one can help me with this

    I am looking for a script that will add text to textfield when you click on the given image.

    For example:
    this is the form.

    <form method="post" action="maker.php" name="maker">

    <input type="text" name="text" />


    <input type="submit" value="Submit" />
    <br>
    Add these Images<br>
    <img src="http://imageurl.com/1.gif" border="0"></a>
    <img src="http://imageurl.com/2.gif" border="0"></a>
    <img src="http://imageurl.com/3.gif" border="0"></a>
    </form>

    when some when will click on desired image it will should add a given value or text to textfield(if they click on image1 it should add 1 to textfield and so on)
    Is it Possible?.If so, can some be kind enough to help me.I will very much apperiacte your help.

    Thanks.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try something like this (not valid HTML, but only used as an example for placement of script):

    Code:
    <html>
     <head>
    
    <script type="text/javascript">
    
    function addMsg(text,element_id) {
    
    document.getElementById(element_id).value += text;
    
    }
    </script>
    
     </head>
    <body>
    
    <form method="post" action="maker.php" name="maker">
    
    <input type="text" id="textfield" name="text" />
    
    <input type="submit" value="Submit" />
    <br>
    
    Add these Images<br>
    
    <a href="#" onclick="addMsg('1','textfield'); return false;"><img src="http://imageurl.com/1.gif" border="0"></a>
    
    <a href="#" onclick="addMsg('2','textfield'); return false;"><img src="http://imageurl.com/2.gif" border="0"></a>
    
    <a href="#" onclick="addMsg('3','textfield'); return false;"><img src="http://imageurl.com/3.gif" border="0"></a>
    </form> 
    
    </body>
    </html>
    Simply change the parts in red (in the above code) to the text you want to add to the text field. Change the parts in blue to match the textfield id (which is in green in the above code).

    Not tested, but hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OMG thanks so much,You rock.It totally worked

    this thread can be closed

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
  •