I
I
Ibishka2020-04-21 11:15:06
PHP
Ibishka, 2020-04-21 11:15:06

How to take select value in php?

All in one index.php file:

<?php
        if (isset($_POST['priceSel'])) {
          echo 'qwdwqdq';
        }
?>
<select class="sel_price sel" id="priceSel" name="priceSel">
            <option value="default">Default</option>
            <option value="ascending">Ascending</option>
            <option value="descending">Descending</option>
          </select>

document.querySelector("#priceSel").addEventListener("change", function () {
  fetch("", {
    method: "post",
    body: this.value,
  });
});


I don't use a form because the page refreshes on submit. It is necessary for me when select change to take value to make request to a DB. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
scottparker, 2020-04-21
@scottparker

so that the page is not updated, use ajax, then the form can also be used (only without submit, but just a button)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question