Well then the question we have is:
How to get select values from the PHP server without "refreshing" the page?
The answer is:
Use AJAX, there are some ways to use Ajax and in my opinion the easiest and most compatible is with jQuery.
Imagine that we have a login/registration page and we want it to send the information to the server more without leaving it under any circumstances, this would be an example similar to yours.
It’s very simple, basically we need 2 files index.html and cadastre.php
complete code: download full code
index.html is simply an HTML file with the common form we already know the difference is in the function ajax
var campos = {nome: "Joao", idade: 32};
$.ajax({
data: campos,// dados que serão enviados para o servidor
url: "cadastro.php", // url a buscar sem fazer refresh (ajax)
type: "POST", // método de envio dos dados (GET,POST)
dataType: "html", // como será recebida a resposta do servidor (html,json)
success: function(data){ // função que tras a resposta quando tudo der certo
alert(data);
},
error: function(){
alert("problema ao carregar a solicitação");
}
});
fields is the variable with the data to be sent, Success is the function that is called when all is over, type is the data sending mode that can also be GET
php.
You simply take the fields, do whatever you want with them and print out an answer
<?php
echo "você enviou os campos: <br/>";
print_r($_POST);
More details on:
jquery.com
ajax function
You can use AJAX for this... use the event
$("select").change(function(){});
select and fire an AJAX call to search the data dynamically. This with Jquery, just for the record. If you already have something from javascript, post together in the question to see.– Daniel Ribeiro
In fact I have nothing in javascript for this feature, the big question is that I do not know how to do it ! I tried to take the example you have on the internet about (state/city search dynamically) to have a base, but I still can’t make the right changes.
– Adriano Carvalho
Give a search in AJAX (asynchronous request) and Jquery, with this you can solve your question.
– Daniel Ribeiro