View Full Version : Addtext to textfield on click

03-24-2007, 01:45 AM
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" />
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>

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.


03-24-2007, 01:56 AM
Try something like this (not valid HTML, but only used as an example for placement of script):


<script type="text/javascript">

function addMsg(text,element_id) {

document.getElementById(element_id).value += text;



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

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

<input type="submit" value="Submit" />

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>


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.

03-24-2007, 02:19 AM
OMG thanks so much,You rock.It totally worked :)

this thread can be closed