简体   繁体   中英

Select dropdown inputting more than one select. Javascript

在此处输入图片说明

I am trying to get my select to only print one address instead of two. When I select TMobile, it will do the print to the input just fine. However, if I also select Verizon, it will also add the Verizon address next to it.

 <select class='cellBox' id='cellSelection'>
  <option value='@tmomail.next'>TMobile</option>
  <option value='@vzwireless.com'>Verizon</option>
 </select>
 <input type='text' class='histBox' id='resultCell'>

Here is my javascript:

 var dropdown2 = document.getElementById('cellSelection2');
 var textbook2 = document.getElementById('resultCell2');
 dropdown2.onchange = function(){
                        textbook2.value += this.value;
                      }

  var dropdown2 = document.getElementById('cellSelection'); var textbook2 = document.getElementById('resultCell'); dropdown2.addEventListener("change",function(){ textbook2.value = dropdown2.value; }); 
 <select class='cellBox' id='cellSelection'> <option value='@tmomail.next'>TMobile</option> <option value='@vzwireless.com'>Verizon</option> </select> <input type='text' class='histBox' id='resultCell'> 

Because you are concatenating the dropdown value in the onchange event.

Change from textbook2.value += this.value; to textbook2.value = this.value;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM