How to set condition for the selected option select with PHP?

Good afternoon. I have the following code:
<section>

 the <h3>RESULTS of OGE/GVA</h3>
 <p>Choose your region:</p>
 <select id="region">
 <option value="0">Not selected</option>
 <option value="saratov">Saratov</option>
</select>

</section>


After the tag select I need to make a condition with PHP - if (ZNACHENIYAMI !== 0) then @include_once("filepath");

How to do it?
March 23rd 20 at 19:43
1 answer
March 23rd 20 at 19:45
Solution
After you have received html page, php have already finished work, and to do include is impossible. Especially for this exists in js, you need to select track changes and send ajax request. After that you can process the data and display the proper unit, the message, etc.
For some reason, nothing displays:
<section>

 the <h3>RESULTS of OGE/GVA</h3>
 <p>Choose your region:</p>

 <form method="post">
 <select name="region">
 <option value="0">Not selected</option>
 <option value="saratov">Saratov</option>
</select>
</form>

</section>

the <script>
$('select').on('change', function() {
$.ajax({
 type: 'POST',
 url: '<?=$_SERVER["PHP_SELF"]?>',
 data: ({region: $(this).val()})
});
});
</script>

<?
$selected_val = $_POST['region']; // Storing Selected Value In Variable
echo $selected_val; // Displaying Selected Value
?>
- giovanna commented on March 23rd 20 at 19:48
@giovanna, and that he should take? The request it sends, and the result is you are not treating yourself, and treating you in this form will not work, for communication via ajax is typically used json, and you want a whole page returned - Rosetta_Koch commented on March 23rd 20 at 19:51
@Rosetta_Koch, please help. I do not understand why I have displays the whole page in data - giovanna commented on March 23rd 20 at 19:54
@giovanna, by the fact that you specified in the url parameter the same page - Rosetta_Koch commented on March 23rd 20 at 19:57
@Rosetta_Koch, and how to do it all on one page, not very hunt for one operation to do the bike and do a bunch of pages? Maybe you can do something all on one page to place? - giovanna commented on March 23rd 20 at 20:00
@giovanna, you can. Write processing the request at the beginning of the page, and at the end of the handler call exitto html output not further worked - Rosetta_Koch commented on March 23rd 20 at 20:03
@Rosetta_Koch, but I is being processed header and footer - Bitrix:
ac04e3c391.png - giovanna commented on March 23rd 20 at 20:06
@giovanna, well, you don't want this hat, so paste your code in the top, like this:
<?php
if( ! empty($_POST['region']) ){
 // Here the processing of an ajax request
exit;
}
require ... // Here the code caps etc

PS Work it certainly is, but I think it's not the best solution for Bitrix, I'm sure there for this is some sort of plugin - Rosetta_Koch commented on March 23rd 20 at 20:09

Find more questions by tags JavaScriptPHP