I have created an Ajax request to populate a select field when the user clicks on a certain specialty to appear only the trained professionals for it. However, when clicking on another specialty the name of other professionals prevail there. I would like to change this, so when the user select type reset what was there and the new select .
<script>
function buscarMedicos(especialidades) {
$.ajax ({
url: 'select.php',
type: 'POST',
async: true,
dataType: 'json',
data:{'especialidades' : especialidades},
success: function (result)
{
if (result != "")
{
for (var i = 0; i < result.length; i++)
{
var aux = result[i];
var campoSelect = document.getElementById("umedico");
var option = document.createElement("option");
option.text = aux;
option.value = aux;
campoSelect.add(option);
}
}
}
})
}
</script>