PDA

View Full Version : Addtext to textfield on click



Neenu
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" />
<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.

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



<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.

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

this thread can be closed