View Full Version : Click Text, enter it in textbox

06-17-2009, 02:36 PM
Hey there

Im looking to have a list of text/links, where once clicked are entered into a text box on the same page... and when a second is clicked - it is appended onto the text that is already in the text box - and so on...

Anyone have any ideas??

Thank youuuuu!

Philip M
06-17-2009, 03:10 PM
Here you are:-

<div id = "mydiv1" onclick = "add(this)">The first text</div><br>
<div id = "mydiv2" onclick = "add(this)">The second text</div><br>
<div id = "mydiv3" onclick = "add(this)">The third text</div><br>
<input type = "text" id = "result" size = "60" readonly = "readonly">

<script type = "text/javascript">
function add(which) {
var val = which.innerHTML;
val = val + " "; // append space as delimiter
document.getElementById("result").value += val;

As I prepare this script, tapping away at the keyboard as Socrates might have done had he owned a PC ....... - Football writer

06-17-2009, 04:53 PM
Thanks Philip, this is a real help.

Unfortunately I cant seem to get it to work

Should I be doing more than simply putting the script in the header and the rest in the body?

Thanks again

Philip M
06-17-2009, 05:26 PM
Stupidly I left off the closing </script> tag.

I have now repaired this in the post.

06-17-2009, 05:30 PM

...the only difference is the </script> missing :)