I have a problem in my code where it takes a value from the database related to the value of the combobox selected by the user and fills in another combobox, until it is working, however when the user of an onchange again it adds the values instead of overwriting I tried to use the reset () function and clear () 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>