Run php within a javascript condition

2

Is it possible to run php within a javascript condition?

Example:

<script>
if(variaveljs==2){
  <?php
  $variavelphp=20;
  ?>
}
</script>

    
asked by anonymous 08.06.2018 / 11:53

1 answer

2

PHP runs on the server side, and this runs always first the Javascript code, which runs on the client. So this condition will not work, if you want to send data from the client to the server you need to use ajax

    
08.06.2018 / 12:50