Add fields on the page as selected option from a drop-down menu select

1

I am creating a form and I want that according to the option selected in the menu a different html code is shown on the screen. I'm using jquery to add the new fields. But with each option selected the new fields are concatenated, that is, every time an option is selected a new value is shown, I wanted it to be shown only once. Follow the code.

$(document).ready(function() {
$( ".form-control" ).change(function(){
    var varURL = $("option:selected", this).val();
    $(".form-group").append('O valor selecionado é: ' + varURL);
});
});
    
asked by anonymous 07.05.2018 / 15:15

1 answer

1

Create a new div within form-group , to receive the values, then using html() you add the values in that div :

$(document).ready(function() {
    $( ".form-control" ).change(function(){
        var varURL = $("option:selected", this).val();
        $("ID_DA_NOVA_DIV").html('O valor selecionado é: ' + varURL);
    });
});
    
07.05.2018 / 15:51