How do I make php wait for the value coming from the Javascript click?

Asked

Viewed 92 times

1

I’m developing a system to evaluate a user (typical of stars), but I’m having problems passing values to PHP.

Javascript code:

   function mouseClick(id){
                var valorVoto = document.getElementById(id).value
                valorVoto = valorVoto.split("#")
                voto = valorVoto[4] 
                <?php $voto = "<script>document.write(voto)</script>"; ?>
            }

PHP code:

    if(isset($voto)){
          echo 'Passou';
    }

When I open the page it does not wait for the click of the button, it simply gives echo.

  • 1

    As the very name of PHP (Hypertext Preprocessor) states, it is a preprocessed language and so can not do what you want. PHP just processes the code and shows the result, so you can only use it in a new request, for example ajax

  • In my star rating system I use ajax, as @Valdeirpsr suggested

  • Thanks for the suggestion of Ajax, but I managed to do only with PHP and JS.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.