2012-04-30 21 views
0

上記のドロップダウンボックスのユーザー選択に基づいてテキスト領域に「変数値」を追加する方法を教えてください。選択に基づく値の追加

<html> 
<head> 

<body> 

<select id="dropdown"> 
    <option value="">None</option> 
    <option value="textArray1">text1</option> 
    <option value="textArray2">text2</option> 
    <option value="textArray3">text3</option> 
    <option value="textArray4">text4</option> 
</select> 

<br /><br /> 

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

<script type="text/javascript"> 

var textArray1 = 'this is going to be a long sting of text for text 1 value'; 
var textArray2 = 'this is going to be a long sting of text for text 2 value'; 
var textArray3 = 'this is going to be a long sting of text for text 3 value'; 
var textArray4 = 'this is going to be a long sting of text for text 4 value'; 

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> 

</body> 
</html> 
+0

それは正常に動作しているようだ、あなたの条件は何ですか? – KBN

答えて

0

があなたのonchange関数内でこの変更を作ってみましょう:

mytextbox.value = mytextbox.value + window[this.value]; //to appened 

ます。また、使用していたかもしれないのeval()この上ここで

はIIがこれまで持っているコードです。 eval()は赤い頭の踏み台の子供ほど人気が​​あります。違いの詳細については this質問をご覧ください。

jsFiddle example

関連する問題