...

View Full Version : Click Text, enter it in textbox



briain
06-17-2009, 01: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!
briain

Philip M
06-17-2009, 02: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>
<br><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;
}
</script>




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

briain
06-17-2009, 03: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
briain

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

I have now repaired this in the post.

briain
06-17-2009, 04:30 PM
Perfect!

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum