How to call a function in the click of the Input Type="date"

1

Friends, I have an issue that I would be happy if you could help me.

I have a calendar created with <input type="date"> of Html5 . I need that when clicking a specific date it takes the value of the date and calls a PHP function that will load a new page passing as a parameter the date that was clicked for this PHP function.

I can do this with a button because I pass as a parameter in the global variable $_GET by calling a PHP that will receive this information but need to do it without the submit the form , but rather at the click of the date. Does anyone know how to proceed ?????

    
asked by anonymous 18.08.2017 / 19:41

2 answers

1

You have several events to choose from input and change suits what you want. The blur also, but only fires when you click out of input .

Example:

var input = document.querySelector('input');
var mostrador = document.getElementById('mostrador');

input.addEventListener('input', log);
input.addEventListener('change', log);
input.addEventListener('focus', log);
input.addEventListener('blur', log);

var contador = 0;

function log(e) {
  mostrador.innerHTML = [
    contador++,'|', e.type, this.value || 'sem valor',
    '<br>' + mostrador.innerHTML
  ].join(' ');
}
#mostrador {
  height: 80px;
  overflow: hidden;
}
<div id="mostrador"></div>

<input type="date">
    
18.08.2017 / 20:10
0

You can use the tag event called: onchange It would look like this:

<input id="Testes" type="date" onchange="alert(this.value)" >  

there you would use a javascript method to parse the value and within that javascript you could in case make a layer for your PHP. I do not have as much practice in PHP, though, I believe you can put PHP code inside script.

If you can not call PHP code ... you can still have your method click on some invisible button inside your HTML code and it executes the PHP method you want.

If you are not comfortable with outgoing calls when typing the date and it completes all values, then try to use the onBlur event (it is only called when the field loses focus.)

    
18.08.2017 / 20:02