0
I’m trying to clear a modal form, I can already clear the other fields with javascript, but I did not have the same result with the list, I tried to do it by the back-end, but I did not have success, so I would like to see the possibility of trying reset the list, would anyone have an idea how to do that? That’s the code block in question! My Javascript file
function justificarRemessa() {
$('#idPeriodoInicio').val("");
$('#idMotivo').val("");
$('#idPeriodoFim').val("");
$('#idUJ').val("");
document.getElementById('idUJ').selectedIndex = "0";
document.getElementById('idUJ').options[0].text = " - ";
// var form = document.getElementById('formCadastrarJustificativa');
// for( var i = 0; i < form.elements.length; i++) {
// console.log(form.elements[i].type);
// if (form.elements[i].tagName === 'SELECT') {
// form.elements[i].selectedIndex = '0';
// }
// }
$('#modalJustificar').modal('show');
}
Cannot change the value of select?
document.getElementById("omeuselect").value = "-";
Where is your code?– lazyFox
If select is inside a form just give one
form.reset()
– fernandosavio
Look at this answer used in another question, maybe I can help. https://stackoverflow.com/questions/44266977/how-to-set-select-box-to-default-value-on-modal-close
– Sumback
tried this way did not work, a form, is not a common form, is a modal :(
– wladyband
@Sumback I will try this solution!
– wladyband
Try calling the modal close function and in it vc set the field value to null.
– Kayo Bruno
@fernandosavio how am I going to use the form.reset() ?
– wladyband
@Sumback didn’t work
– wladyband
@fernandosavio gave this message Uncaught Typeerror: $(...)[0]. reset is not a Function
– wladyband
Just you select your
<form>
withdocument.getElementById()
or something similar and then use the methodreset()
form so that each input returns to its initial state. Look a very simple example– fernandosavio