Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2007, 10:52 AM   PM User | #1
adastra
New to the CF scene

 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
adastra is an unknown quantity at this point
copying text from a string into an input field

Hi, I'm a total javascript noob, so I have a rather stupid question;

How can I copy a small text (tag) from a document into an input box? I want to create a simple tagging function for a news script, and above the input fields for the tags, I want to display all the existing tags. So the user can just click on a tag, and it's automatically entered into the input field, comma seperated.

Thanks in advance!
adastra is offline   Reply With Quote
Old 01-31-2007, 03:21 AM   PM User | #2
1212jtraceur
Regular Coder

 
Join Date: Oct 2006
Posts: 206
Thanks: 1
Thanked 0 Times in 0 Posts
1212jtraceur is an unknown quantity at this point
I'm not quite sure what you mean by the last sentence, but I'll take a shot at helping you:

A textarea's value and an input's value can be changed using the value property. An anchor (or a button) can do things using the onclick property. Putting those two together, you get:

PHP Code:
<textarea id="text"></textarea>
<
input type="text" id="text2" />
<
a href="#nowhere" onclick="document.getElementById('text').value += 'text1 '; document.getElementById('text2').value += 'text2 ';">click me</a
1212jtraceur is offline   Reply With Quote
Old 01-31-2007, 07:38 AM   PM User | #3
ChanLFC
New Coder

 
Join Date: Nov 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
ChanLFC is an unknown quantity at this point
Hi adastra,

I think this is what you are looking for. Just try the following,

<html>
<head>
<style>
td { border:solid 1px red; cursor:hand; color:white; background:blue; font-weight:bold; font-family:Tahoma; font-size:10pt; }
</style>
<script>
function add(tag) { document.getElementById('txtA').value += tag + ", "; }
</script>
</head>
<body>
<span style="font-weight:bold; font-family:Tahoma; font-size:10pt; color:blue;">
Choose your favourite clubs
</span>
<table border="0" cellpadding="2" cellspacing="10">
<tr>
<td onclick="add(this.innerHTML);">Liverpool</td>
<td onclick="add(this.innerHTML);">Celtic</td>
<td onclick="add(this.innerHTML);">Inter</td>
<td onclick="add(this.innerHTML);">Bremen</td>
<td onclick="add(this.innerHTML);">Deportivo</td>
<td onclick="add(this.innerHTML);">Ajax</td>
<tr>
</table>
<textarea id="txtA" rows="10" cols="100">
</textarea>
</body>
</html>
__________________
Chandan
Share knowledge, it only expands
ChanLFC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:18 PM.


Advertisement
Log in to turn off these ads.