When filling in the Date field, perform a jQuery action

Asked

Viewed 2,160 times

2

I have a field data and I need that when I finish filling the date... Perform 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">
  • 1

    yes and what is the problem with its masked functionData(this) ?

  • just put your jquery method here: onkeyup="mascaraData(this);metodojQuery();" or do according to my answer below.

  • Yes, I would like you to complete the field completion, perform a new function, which I will do for customer listing, for example.

  • But to make your list, first I need to know what that list would be, agree, and where you’re removing your list from.

  • I will make a return Json, for listing of customers that is in the database... The scheme would be as follows: SELECTS DATE, SELECTS THE CLIENT, WHICH IN TURN LISTS THE CALLS MADE TO THIS CLIENT...

  • Make an exit with your echo json_encode($array_dados).

  • and then capture it, as in this reply: http://answall.com/questions/77326/como-fazer-para-trazer-tabela-comdados-ao-retornar-de-um-insert/77697#77697

Show 2 more comments

4 answers

3

The solution to your problem would be something like this:

$(function(){

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

});

2

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

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

$('#dp1').blur(function(){
  var val = $('#dp1').val();
   if(val != ""){
     mascaraData(val);
   }
});

2


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

An example:

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

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

I believe . Blur will apply better to your case.

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

0

we can also add the onBlur event directly into 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">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.