I'm trying to validate a Form and I've managed to get it to work but I changed an id or class or something I don't know that suddenly my code has been screwed up and I'm not able to see the error, am I stupid or after so much time I'm unable to see him.
<form class="contacto" id="form1 " action="?action=<?php echo isset($obj_categoria) ? 'actualizar' : 'registrar'; ?>" method="POST" style="margin-bottom:30px;">
<input type="hidden" name="id" value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('acronimo') : ''; ?>" />
<table style="width:500px;">
<tr>
<th style="text-align:left;">Acronimo</th>
<td>
<input id="acronimo" class="form-control" type="text" name="acronimo" value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('acronimo') : ''; ?>" style="width:100%;" />
</td>
<th style="text-align:left;">Categoria</th>
<td>
<input id="categoria" class="form-control" type="text" name="categoria" value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('categoria') : ''; ?>" style="width:100%;" />
</td>
</tr>
<tr>
<th style="text-align:left;">Registro Calidad</th>
<td>
<select class="form-control" id="registro_calidad" name="registro_calidad">
<option value=""><?php echo isset($obj_categoria) ? $obj_categoria->__GET('registro_calidad') : ''; ?></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="boton">Guardar</button></td>
<td colspan="2">
<form action="index.php">
<input class="btn btn-primary boton" type="reset" value="Limpiar" />
</form></td>
</tr>
</table>
</form>
And this the code:
$(function() {
$(".boton").click(function(){
$(".error").fadeOut().remove();
if ($(".acronimo").val() == "") {
$(".acronimo").focus().after('<span class="error">Ingrese su nombre</span>');
return false;
}
if ($(".categoria").val() == "") {
$(".categoria").focus().after('<span class="error">Ingrese un asunto</span>');
return false;
}
});
$(".acronimo, .categoria").bind('blur keyup', function(){
if ($(this).val() != "") {
$('.error').fadeOut();
return false;
}
});
});
It seems you deleted part of the html code
Current code:
Correct code:
or maybe you wanted to put:
Here is the code of how it should look: