0
<button onclick=run(4)>
clickme
</button>
<script>
function run(a){
alert(a);
<?php
if('<script>document.write(a)</script>'==4){
echo 'runing php';
echo '<script>alert(a);</script>';
}
   ?>}
</script>

I'm new to php,i'm not able to get how the process is going on here.here i want to get value from javascript into the php variable...

Abhishek
  • 351
  • 1
  • 3
  • 18
  • 1
    PHP runs on the server before the JavaScript is sent to the client to run in the browser, so your code cannot work. You have a lot of learning to do yet and this is not the place to teach you, so I am voting to close this question as too broad. – vascowhite Jan 29 '17 at 04:37
  • you can send javascript value to php using ajax . try it ! – M. Alim Jan 29 '17 at 05:23

1 Answers1

0

this should be your html

     <button onclick=run(4)>
       clickme
     </button>
     <script>

then in you js file use jquery like

   $(document).ready(function(e){
      function run(val){
        $.post('yourfilename.php',{yourvariable:val},function(response){
        alert(response); // with alert you can see the feeback from php.
        });

} });

in php file get the value of jquery like this

   $value = $_POST['yourvariable'];
  echo $value; //this value will be return to your ajax call as response
M. Alim
  • 153
  • 16