1
I’m trying to make a "selection menu" (selectmenu
) is reset when I enter a value by hand in a text field, but although I have tried numerous solution I searched here in Stack Overflow and other sites, none worked.
Below is my HTML code:
<div>
<label>Selecione Um Prazo Padrão:</label>
</div>
<div>
<select name="menuPrazo" id="menuPrazo" class="menuPrazo">
<option value="*" selected="selected">Escolha um Tipo de Prazo</option>
<option value="1">A Vista</option>
<option value="30">Prazo Normal</option>
<option value="15">Prazo Estendido</option>
</select>
</div>
<div>
<label>Ou Informe Um Prazo Personalizado:</label>
</div>
<div>
<input type="text" name="prazoManual" id="prazoManual" class="prazoManual" value=""></input>
</div>
Below the code in Javascript:
$(".menuPrazo").on("change", function () {
$("#prazoManual").val("");
});
$(".prazoManual").on("change", function () {
$('#menuPrazo').prop('selectedIndex',0);
});
In addition to the option contained in the above code, I have tried the following options:
$("select#menuPrazo").selectmenu("index", 0);
or
$("#menuPrazo").val("");
or
$("#menuPrazo").refresh();
Perfect solution! At first it didn’t work in my code, although it worked correctly in Jsfiddle. After much breaking my mind I discovered that the reason for not working was the loading order of the libraries "Jquery", "Jquery UI" and "Jquery Mobile". When changing the loading order to this order I mentioned, everything worked correctly.
– Daniel Silva