I have a problem with the following code.
$('#selDocTipo').change(function () {
var $optionSelected = $("#selDocTipo option:selected")
var TipoDocId = $optionSelected.val();
// dni 8 pasaporte 10 tarjeta de secretaria
$("#txtNumDocProm").val("");
$("#txtNumDocProm").attr('disabled', false);
if (TipoDocId == 47) {
//dni
$("#txtNumDocProm").attr('maxlength', '8');
$("#txtNumDocProm").attr('onkeypress', 'ValidaNumvit(event)');
} else if (TipoDocId == 51) {
//Pasaporte
$("#txtNumDocProm").attr('maxlength', '12');
} else if (TipoDocId == 52) {
//Carnet Extranjeria
$("#txtNumDocProm").attr('maxlength', '12');
}
});
My html is this:
<div class="form-group">
<label class="col-md-2 control-label">Tip. Doc.. : </label>
<div class="col-md-3">
<select class="selectpicker" id="selDocTipo" >
<option value="47">DNI</option>
<option value="51">Pasaporte</option>
<option value="52">Carnet de Extrangeria</option>
</select>
</div>
<div class="col-md-3">
<input type="text" id="txtNumDocProm" class="form-control" placeholder="Nº de Documento" />
</div>
</div>
my ValidaNumvit function is.
function ValidaNumvit(event) {
var keycode = event.which;
if (!(event.shiftKey == false && (keycode == 46 || keycode == 8 || keycode == 37 || keycode == 39 || (keycode >= 48 && keycode <= 57)))) {
event.preventDefault();
}
}
It happens that when I select first DNI, it fulfills everything, but then if I select another option it will only accept numbers. It's like if I saved it in cache, or I do not know, but when I choose another first option, it accepts all the characters, but I select dni
, I'm left with only numbers until I refresh the page .
Does anyone know why that happens?