0

I want to set php value as per javascript variable.

I want <?php $result = "x" ?> instead of alert("You selected: " + x);

In this code:

<script type="text/javascript">
            function selectOption() {
                var x = document.getElementById("item1").value;
                alert("You selected: " + x);
                if (option == "Select Item") { 

                    return true; 
                }<?php
  $stmt = $user_home->runQuery('SELECT * FROM item ORDER BY Sr ASC ');
    $stmt->execute();

    if($stmt->rowCount() > 0)
    {

        while($row=$stmt->fetch(PDO::FETCH_ASSOC))
        {
            extract($row);
            ?>else if (option == "<?php echo $IRN ?>") {
                return true;
            }
    <?php }} ?>

                    return false;
            }
        </script>
BTC
  • 71
  • 7
  • [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – hassan Nov 12 '17 at 07:48
  • Where is `option` defined in the javascript code? To set a javascript variable as a php variable without reloading you need to use ajax or fetch - all calls will be asynchronous however so you need to handle the server side and client side responses – Professor Abronsius Nov 12 '17 at 08:16
  • @RamRaider Can you please help me with the code. – BTC Nov 12 '17 at 08:26
  • The code that you have will not do what you are expecting - as @hassan is suggesting with the link about server versus client side programming. If you refer to the answer I gave yesterday it has a simple ajax function that you could use to sent asynchronous ajax calls to a PHP script – Professor Abronsius Nov 12 '17 at 08:32

0 Answers0