3
This is my HTML list;
<div class="form-group">
<label class="col-sm-2 control-label"><fmt:message key="label.sagresPessoal.tela.prestacao.unidade.jurisdicionada" /></label>
<div class="col-sm-8">
<select id="idUJ" name="prestacaoFolha.idUnidadeGestora" class="form-control select2 ">
<option value ="">-</option>
<c:forEach items="${listPessoaJuridica}" var="PJ">
<option value="${fn:replace(PJ.codigo,'.','')}">${PJ.nome}</option>
</c:forEach>
</select>
</div>
</div>
I can empty the other fields like this;
$('#idPeriodoInicio').val("");
$('#idMotivo').val("");
$('#idPeriodoFim').val("");
But I didn’t have the same success with the list, I tried that way;
$('#idUJ option').each(function(index) {
if (index !== 0) {
$('#idUJ').val().splice(0,$('#idUJ').val().length);
}
});
How should I do?
Nice and compact. But by the example in the question he wants you to keep the first item. It would be something like
$("#idUJ").empty().append('<option value="">-</option>');
(Little world huh, Bins? P)– Ronaldo Araújo Alves
Really the world is very small :-) Considering what you said, this is how you commented.
– Bins