Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a text area via data from drop down 1

Status
Not open for further replies.

qwert62

Programmer
Oct 12, 2000
28
0
0
US
Here is my challenge. I have a textarea that a user currently keys in general data. I need to give user an option to enter in certain keywords. These keywords need to come via a drop down. For example, the user needs to insert the phrase "[[blue color]]" amoungst existing text in the text area. The user does not want to have to type [[blue color]], but select it via a drop down.

Anyone have any thoughts on how to do accomplish this?

My thought is to have user click desired text in drop down. I then want to create a keystroke that will copy the drop down value into the position in textarea where the cursor sits. (Similair to Copy/Paste). Any ideas if this is possible?

Thanks in advance.

Dave
 
Here is a quick idea... This uses VBscript but I'm sure it could be done with javascript as well...

<HTML>
<HEAD>
<script language=vbscript>
sub addchoice()
form1.mytext.value = form1.mytext.value & form1.choices.value
form1.choices.selectedIndex = 0
end sub
</script>
</HEAD>
<body>
<form name=form1>
<select name=choices onchange=addchoice()>
<option value=&quot;&quot; selected>Choose a color
<option value=&quot;[[blue color]]&quot;>[blue]
<option value=&quot;[[red color]]&quot;>[red]
</select>
<BR>
<BR>
<textarea rows=10 cols=50 name=mytext></textarea>
</form>
</body>
</html>

Hope that helps...
mwa
 
if you wanted to convert that to javascript due to vbscript copatibility issues this should do it
<script language=&quot;javascript&quot;>
function addchoice() {
form1.mytext.value = form1.mytext.value + form1.choices.options[form1.choices.selectedIndex].text
}
</script>
</HEAD>
<body>
<form name=form1>
<select name=choices onchange=addchoice()>
<option value=&quot;&quot; selected>Choose a color
<option>[blue]
<option>[red]
</select>


no need to add the value attrib seeing as you're not passing this in anyway out of the page but just using it for functionality I dare to learn more
admin@onpntwebdesigns.com
 
Thanks very much. It worked like a charm!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top