0
I have a problem in my code where it takes a bank value related to the value of the combobox selected by the user and fills in another combobox, until then it is working but when the user gives an onchange again it adds the values instead of overwriting tried to use the reset() and clear() function of jquery did not work follow the code below:
<script>
$(document).ready(function() {
$("#button").change(function() {
var valor = $("#button").val();
alert(valor);
$.post("procura.php",
{valor: valor},
function(data){
alert(data);
var resultado = data.split(",");
for ( var i = 0 ; i < resultado.length ; i++ ){
var option = $("<option></option>").appendTo($('#result'));
option.attr("value", resultado);
option.html(resultado[i]);
}
document.getElementById("form").reset();
});
});
});
</script>
</head>
<body>
<select id="button">
<option value="AVT">AVT</option>
<option value="MMFT">MMFT</option>
<option value="RUNIN">RUNIN</option>
</select>
<select id="result" name="result">
<option value=""></option>
</select>
you give me the freedom to edit the title of your question so that it makes more sense? " How to remove options from a select before updating it with others, via Javascript"
– Leandro Angelo