i want easy Javascript code to change textarea value upon <select><option>

please help me, I have some textarea data which needs to be changed when the user select different option from a <select>.

can you please give me some javascript easy code to do that

please i don't want jquery things

Answers


You can use the onchange event. I can't write the code for you because I don't know what your current code looks like (and that's not really what this site is about), but I can give you an example:

var select = document.getElementById("mySelect");
select.onchange = function ()
{
    // get a reference to the textarea element
    var tArea = document.getElementById("myTextArea");

    // Set the text to the value of the currently selected option
    tArea.value = this.options[this.selectedIndex].value;
}

Why don't you want to use jQuery? It's about 10 times easier, not just to use but also to debug and it has alot of community support


Try Following it may help...........

< script type="text/javascript">
    functionName(this){
    var tArea = document.getElementById("myTextArea");
    if(this.value=="1"){
    tArea.value="1"
    }else if(this.value=="0"){
       tArea.value="0"
  }
< /script>

< select onchange="functionName(this);">
    < option value="1">Available< /option>
    < option value="0">  Not Available< /option>
 < /select>

Need Your Help

Is there a way to pass a method reference in Java?

java function methods reference parameters

This is quite difficult to phrase, but I need to be able to link a specific method to an object. More specifically, I'm making a graphics-oriented GUI, and I want to be able to assign an arbitrary ...

Is there a JavaScript library that does Rijndael 256bit encryption like PHP?

php javascript encryption mcrypt rijndael

I've been extensively using Rijndael 256bit encryption in PHP for my API and would like to use it for my API wrapper that is written in JavaScript as well, but I've been unable to find a solution t...