I have the next html form:
<form role="form" action="MAILTO:alejandro@distal.com.ar " method="post" enctype="text/plain" id="form-contacto">
<div class="row">
<div id="form-column" class="col-xs-12 col-sm-6 col-md-6 col-lg-6 col-sm-push-3 col-md-push-3 col-lg-push-3">
<div class="form-group">
<label for="name" class="sr-only">Nombre:</label>
<input type="textbox" placeholder="ingrese su nombre" name="name" id="name" class="form-control">
<div id="nameRequiredError" class="alert alert-danger" role="alert">El nombre es obligatorio.</div>
<div id="nameFormatError" class="alert alert-danger" role="alert">Solo se permiten letras y puntos.</div>
</div>
<div class="form-group">
<label for="email" class="sr-only">Correo electrónico</label>
<input type="email" placeholder="ingrese su correo electrónico" name="name" id="email" class="form-control">
<div id="emailRequiredError" class="alert alert-danger" role="alert">El dirección de correo electrónico es obligatoria.</div>
<div id="emailFormatError" class="alert alert-danger" role="alert">Ingrese un correo electrónico válido.</div>
</div>
<div class="form-group">
<label for="message" class="sr-only"></label>
<textarea name="" id="message" cols="30" rows="10" class="form-control" placeholder="Escriba su mensaje..." sizable="false"></textarea>
<div id="messageRequiredError" class="alert alert-danger" role="alert">Ingrese un mensaje para enviar.</div>
<div id="messageFormatError" class="alert alert-danger" role="alert">El mensaje no tiene nigún caracter alfanum&eactue;rico.</div>
</div>
</div>
</div>
<div class="row">
<div id="form-column" class="col-xs-6 col-sm-3 col-md-3 col-lg-3 col-xs-push-6 col-sm-push-6 col-md-push-6 col-lg-push-6">
<submit class="btn btn-primary form-control"> Enviar >> </submit>
</div>
</div>
</form>
I want to validate the data entry when the input loose focus, but i haven't catch the focus out. I tried all this:
$('#name').blur(function(event) {
alert("blur");
});
$('#name').focusout(function(event) {
alert("focusout");
});
// $('#name').live('focusout', function(){
// alert("live(focusout)");
// });
// $('#name').live('blur', function(){
// alert("live(blur)");
// });
$('#name').trigger('focusout', function(){
alert("trigger(focusout)");
});
$('#name').trigger('blur', function(){
alert("trigger(blur)");
});
$('#name').on('focusout', function(){
alert("on(focusout)");
});
$('#name').on('blur', function(){
alert("on(blur)");
});
but these don't work, any know why? I'm turned crazy! thanks for everyone that will read this!
Your code appears to work fine in JS Fiddle http://jsfiddle.net/dfkg7dha/2/
But try adding the event handler inside the ready
function. Code inside here will ony run once the DOM is ready for JavaScript to execute.
$(document).ready(function () {
$('#name').blur(function(event) {
alert("blur: perform validation here");
});
});
and also for sanity make sure the JQuery JavaScript has been referenced on the page.