Populate an html textarea from a drop down list

Hi,

I have an html drop down list, and need to have a textarea populated with the choice from the drop down list.

Thanks for any help.
LVL 1
taborrgAsked:
Who is Participating?
 
Joshua1909Commented:
Hi tabborg,

Can you paste the final code you're using.

I've attached a working html file with the code in it.


Cheers,
Josh
textarea.html
0
 
Joshua1909Commented:
Hi,

This will work, but I can't take credit for the code:

HTML
<textarea id="mytext"></textarea>

<select id="dropdown">
    <option value="">None</option>
    <option value="text1">text1</option>
    <option value="text2">text2</option>
    <option value="text3">text3</option>
    <option value="text4">text4</option>
</select>

Open in new window


Javascript
<script type="text/javascript">
    var mytextbox = document.getElementById('mytext');
    var mydropdown = document.getElementById('dropdown');

    mydropdown.onchange = function(){
          mytextbox.value = mytextbox.value  + this.value; //to appened
         //mytextbox.innerHTML = this.value;
    }
</script>

Open in new window


Links:
http://jsfiddle.net/kjy112/kchRh/
http://stackoverflow.com/questions/5263839/how-to-fill-in-a-text-field-with-drop-down-selection

Cheers,
Josh
0
 
ProculopsisCommented:
Take a look at this jsfiddle
.
$("#source").change(function() {
    $("#target").val( $("option:selected", this).text() );
});

Open in new window

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
taborrgAuthor Commented:
Joshua1909 - Looks promising, I will try this.

Proculopsis - I don't understand this.  Where and how would it be used?

Thanks!
0
 
taborrgAuthor Commented:
Joshua1909,

I copied and pasted all the code, and it doesn't put anything into the textarea.
0
 
taborrgAuthor Commented:
0
 
taborrgAuthor Commented:
Hey Josh,

Your code works fine.  My problem may have had to do with how I placed the javascript - the code that's working is in a function.

Your answer got me to the solution.

Thanks.


The code:


function addOption(x) {

sOption=document.getElementById('textBox1').value;
sOptions=sOption.split("\n");
 if (sOption == '') {document.getElementById('textBox1').value=x+"\n";}
 else {  
  if (sOptions.length > 1) {document.getElementById('textBox1').value=sOption+x+"\n";}
  else {document.getElementById('textBox1').value=sOption+"\n"+x+"\n";}
 }
document.getElementById('textBox1').focus();
}


Source:

http://www.tek-tips.com/viewthread.cfm?qid=1071319
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.