When filling in the Data field, execute a jQuery action

0

I have a data field and need that when I finish filling the date ... Execute a function to list a SELECT form.

<input id="dp1" class="input-small" onkeyup="mascaraData(this);" name="data"  type="date" placeholder="DD/MM/YYYY" data-date-format="dd/mm/yyyy"  required="required">
    
asked by anonymous 31.08.2015 / 20:51

4 answers

1

I believe that what you want and that when leaving the date field, the event is triggered. For this you can use the .focusout event that is triggered just as your element loses focus.

An example:

$('#dp1').focusout(function(){
    //Coloque aqui o código que você precisa
});

Another event that can be used is .blur , the difference between .focusout and .blur is that blur is fired when the element loses focus, the .focusout is fired when the element, or any other element within it, loses focus.

I believe that .blur will apply to you better.

$('#dp1').blur(function(){
    //Coloque aqui o código que você precisa
});
    
31.08.2015 / 21:20
2

The solution to your problem would look something like this:

$(function(){

    $('#dp1').on('blur', function(){
     alert('Sua lista!');
    });

});
    
31.08.2015 / 20:57
1

Using this way you are firing the event with each key pressed in the focus element, the correct one would be to use .blur () because the event would only be triggered when leaving the field or having a date entered and you would only validate if the field is filled in.

The event onkeyup occurs when the user releases a key (on the keyboard) a date would have an average of 8 digits and in the case 8 function shots!

$('#dp1').blur(function(){
  var val = $('#dp1').val();
   if(val != ""){
     mascaraData(val);
   }
});
    
31.08.2015 / 21:16
0

We can also add the onBlur event directly to the input.

 <input id="dp1"  onblur="mascaraData(this);" class="input-small" onkeyup="mascaraData(this);" name="data"  type="date" placeholder="DD/MM/YYYY" data-date-format="dd/mm/yyyy"  required="required">
    
31.08.2015 / 21:36