Please tell me there is a js variable taken from input. How to put this value in php variable?

$(document).ready(function() { var rowCount = $('#one').val(); alert (rowCount); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="one" value="10" type="text"> <?php $pages="///Должно быть 10//"; echo "$pages"; ?> 

  • one
    phpfaq.ru/newbie/na_tanke#js read to full understanding - Alexey Ten
  • Setting the php variable in js code will not work. Save the value of the variable by making an AJAX request - Anton Bogomolov

2 answers 2

php is running on the server. js is executed in the user's browser. php doesn't know anything about js and js doesn't know anything about php. When js is executed, php has already worked and died.

 <? $value=10;?> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="one" value="<?=$value;?>" type="text"> <?php $pages=$value; echo "$pages"; ?> 

Well, the value of 10 in the $ value variable should come from a database, from cookies or from a session.

    Something like this ?

     $(document).ready(function() { var rowCount = $('#one').val(); alert (rowCount); }); 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="one" value="10" type="text"> <?php $pages="<script> let z = document.getElementById('one').value; document.write(z); </script>"; echo "$pages"; ?>