0

I have a simple drop-down box and I am successfully using Javascript to automatically fill a textbox when a drop-down item is selected.

Once I edit any of the textbox's automatically filled text, or use a "Clear" button to erase textbox, the drop-down list no longer replaces fills the textbox.

How can I continue to use the drop-down box once the user has altered the textbox?

JSFiddle Version

HTML code:

<select id="dropdown" onchange="preset();">
    <option value="">Select a person:</option>
    <option value="Abe" >Abe</option>
    <option value="Bob" >Bob</option>
    <option value="Cal" >Cal</option>
    <option value="Dan" >Dan</option>
</select>

<input type=Submit value="Clear" onclick="document.getElementById('mytext').value='';">

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

Javascript code:

function preset() {
    document.getElementById("mytext").innerHTML=document.getElementById("dropdown").value
}
4

2 に答える 2

2

innerHTMLある場所と別の場所で使用しvalueます。両方で使用valueすると修正されます。

デモ

于 2012-08-30T15:40:11.450 に答える
0

送信ボタンを次のように更新します。

<input type=Submit value="Clear" onclick="document.getElementById('mytext').innerHTML='';">
于 2012-08-30T15:41:34.157 に答える