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...

2
  • 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. Commented Jan 29, 2017 at 4:37
  • you can send javascript value to php using ajax . try it ! Commented Jan 29, 2017 at 5:23

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.