Changing the php variable by javascript


I have a button with onclick function. It passes a variable $x into the java script. Shortly what i want to do is to pass the $x="aaa" to the javascript, and make the function to change this variable into lets say $x="bbb" without refreshing the website. So i would be able to click it all the time and the js could change the value of given variable. I mean the content variable going from button to javascript would be changed depending on js function code. This may sound complicated i am really sorry for that. Any ideas? (the code below i just made up because it would be to long to explain here all my code that is very long now)

<?php x = "aaa";  ?>

<button onClick="someFunction(<?php $x ?>)"></button>

function someFunction (x){
//what can i do here to make this "aaa" string in variable change
//into for example "bbb" on clicking it again?

You can't change server side language value from client script

All you can do is to pass that php value to javascript

Like this

<button onClick="someFunction(<?php echo $x; ?>)"></button>

But you can do like it

Try like this


  method: "GET",
  url: "some.php",
  data: { x: "John" }
  .done(function( msg ) {
    <?php x=$_COOKIE["X"]; ?>




How I can cut it off from button arguments


<button id="myButton" onclick="someFunction(<?php $x ?>)"></button>


    var onclick=$(this).attr("onclick");
    var str="Hellow world";
    var someFunction="someFunction('"+str+"')";