jQuery: Change php variable with jQuery?!

I have an php variable like this:

$pageClass = 'cube';

And I want to be able to change this variable with jQuery and the jQuery is on the same page? Can this be done???

Thanks in advance :wink:

jQuery (which is JavaScript code) doesnā€™t start to run until PHP has fully finished.

  1. Client requests page from server
  2. Server processes PHP and serves the end result as an HTML page
  3. Client receives the HTML page
  4. Client processes JavaScript

So what if i Want to change an variable in a iframe. In the page within the iframe lets say from an dropdown menu with an ā€œonChangeā€?

By the time the page gets to the web browser, all of the PHP code has long since been executed.
If you want PHP to behave differently based on different inputs, you will need to send that info as a request to the server.
That can be done either by sending the data to a request for a new page (commonly by submitting a form request), or it can be done as a partial part of the page without reloading the page by using an AJAX request.

Thereā€™s a good book that takes you through how to do such things properly, called Bulletproof Ajax

Thanks alotā€¦ Iā€™m on it :wink: