You can use Eventlistener to listen when a key is pressed and keycode to check which key is, and then Xmlhttprequest to send to php
Since you didn’t say if you use jquery, follow the example in js pure:
var input_busca = document.querySelector('#searchinputid')//Seleciona a input
input_busca.addEventListener('keypress', function (e) {
var key = e.which || e.keyCode;
if (key === 13) { // 13 = verifica se a tecla é o enter, 13 = enter
alert("Valor local: " + input_busca.value)//Exibe o valor local
var xhr = new XMLHttpRequest();
xhr.open('GET', 'get.php?searchinputid=' + input_busca.value, true);// Informações para enviar ao php
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
alert("Resposta servidor: " + this.responseText);//Resposta do servidor
};
xhr.send();
}
});
<input id="searchinputid" type="text" class="searchinput"
name="txtbuscan" placeholder=" Search..." autocomplete="off">
Sample code from get.php
<?php
$variavel = $_GET['searchinputid'];
echo $variavel;
Your HTML is invalid. The input tag does not accept closure. This can cause your page to behave correctly in all browsers.
– Oralista de Sistemas