チェックボックスが大部分を占めるフォームがあります。チェックボックスにはそれぞれ、JavaScript配列内のアイテムに対応するID「値」があります。配列アイテムは、テキストエリアに入力するテキストを保持します。
サイトをクリーンアップするためのドロップダウンボックスをいくつか含めたいと思います。ただし、ドロップダウンオプションに配列IDを割り当てることができないようです。これはselectboxオプションで実行できますか?タブを使用せずに選択ボックスをシミュレートするための回避策はありますか?
私のhtmlは基本的に:
<div>
<input type=checkbox id=array1 name=textArray></input>
<input type=checkbox id=array1 name=textArray></input>
<input type=checkbox id=array1 name=textArray></input>
...
<select><option 1><option 2>...</select>
</div>
<div>
<form>
<textarea id=outPut></textarea>
</form>
</div>
そして私のjsは:
var textArray = {
array1: 'some text here',
array2: 'some more text',
array3: 'some other text',
...
array90: 'the last text'
};
// variable assigned to chosen item
var selectedInputs = document.getElementsByName("textArray");
for (var i = 0; i < selectedInputs.length; i++) {
selectedInputs[i].onchange = function() {
chosenItem = this;
printText();
};
}
// Script to add items to the Comments section text area
var mytextbox = document.getElementById('outPut');
var chosenItem = null;
function printText(){
if(chosenItem !== null){
mytextbox.value += textArray[chosenItem.id] + "";
// resets the radio box values after output is displayed
chosenItem.checked = false;
// resets these variables to the null state
chosenItem = null;
}
}
js配列内のアイテムを選択ボックスの選択肢の1つに関連付けるにはどうすればよいですか?