Copying Outliers

I am trying to copy two dropdown values ​​and add them to a textbox. I copy one just fine, but can't copy two. I am trying to copy the value "sum" and the value "type" concatenates them and pastes them into a textbox. My code:

function copy() {
    var sel = document.getElementById("amount");

    var text = sel.options[sel.selectedIndex].value;
    var out = document.getElementById("textarea");
    out.value += text + "\n";
}

      

+3


source to share


2 answers


var sel1 = document.getElementById("amount");
var sel2 = document.getElementByid("type");
var amt = sel1.options[sel1.selectedIndex].value;
var typ = sel2.options[sel2.selectedIndex].value;
var out = document.getElementById("textarea");
out.value += amt + " " + typ + "\n";

      



+1


source


You might want to rename your field with the name "type" as it might be the name of a reserved variable.

Also, I can't see where you are pulling the type value? Try the following:



function copy() {
    var sel = document.getElementById("amount");
    var textInput = document.getElementById("some_type");
    var text = sel.options[sel.selectedIndex].value + textInput.value;
    var out = document.getElementById("textarea");
    out.value += text + "\n";
}

      

0


source







All Articles