good day. I have a PHP form with a select and an input in HTML, the select with id = idTypeDocument has three options: ID, Passport, Card.
div class="col-sm-4"><label>Tipo de documento de identidad</label><select class="form-control input-sm" id="idTipoDocumento" name = "nTipoDocumento">
<option value="ID">ID</option>
<option value="CARNÉ DE RESIDENTE">Carné de Residente</option>
<option value="PASAPORTE">Pasaporte</option>
</select>
</div>
if the user selects ID then via jQuery I set the HTML input pattern with id = idDocument like this:
$('#idTipoDocumento').on('change', function () {
var documento = $(this).val();
if(documento=="ID")
{
$('#idDocumento').attr("pattern", '[0-9]{8}-[0-9]{1}');
$('#idDocumento').attr("placeholder", "FORMATO DUI ########-#");
}
and it works for me, the problem is that when the user selects Passport or meat then I want the input to have no pattern set, at the moment I use this but it does not work for me
$('#idTipoDocumento').on('change', function () {
var documento = $(this).val();
if(documento=="DUI")
{
$('#idDocumento').attr("pattern", '[0-9]{8}-[0-9]{1}');
$('#idDocumento').attr("placeholder", "FORMATO DUI ########-#");
}
if(documento=="CARNET DE RESIDENTE")
{
$('#idDocumento').removeAttr("pattern");
$('#idDocumento').attr("placeholder", "");
}
if(documento=="PASAPORTE")
{
$('#idDocumento').removeAttr("pattern");
$('#idDocumento').attr("placeholder", "");
}
});
Could you help me?
the input code is as follows
<div class="col-sm-4"><label>Número de documento de identidad *</label><input type="text" title="especifique número de documento" id="idDocumento" name = "nDocumento"class="form-control" autofocus required oninvalid="setCustomValidity('Debe ingresar número de documento válido')" oninput="setCustomValidity('validar valor')"></div>