0
Hello,
I am a relatively new programmer in php and I am developing a website. It is a site where there is a list of companies. And I wanted to implement in it, search filters, the first of them being a select "Select your city":
<form method="post" action="lista.php" id="Cidade" name="Cidade">
<label for="cCidade">Selecione sua Cidade</label>
<select id="cCidade" name="tCidade">
<option>Selecione a Cidade</option>
<option value="Farroupilha">Farroupilha</option>
<option value="Caxias do Sul"default>Caxias do Sul</option>
</select>
</form>
I want when the user uses the select
, the results are sent to a iframe
on the screen (the "list.php"), which is the listing of companies as I said earlier. But I want this submission, not update the page and not need a button to be sent, IE, whenever the user uses another option of select, the search totally changes.
Hello Andrew! Thank you so much for helping! Just a question, if I want to create a variable with this result I use which syntax? And if it’s the same document?
– Nicolas S.
If the return of your back-end is just text, you will use the attribute
responseText
of the xhttp variable. If by chance you return a list of companies in JSON format, for example, you can do the following:var myjson = JSON.parse(xhttp.responseText);
. Ready, its variablemyjson
will be an objectJavaScript
manipulable, containing all the data returned from PHP. Just go mount your page.– Andrew Ribeiro
Ahh yes, this is also a question, but if I want to create a variable to receive which is the current city selected by the user?
– Nicolas S.
Simple. The current city is stored in
select.value
. If you want to save this in a variable, just dovar atual = select.value;
– Andrew Ribeiro
I did some tests here and when I create this variable and try to display it on the screen, it appears as empty, because?
– Nicolas S.