SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery: Change php variable with jQuery?!

    I have an php variable like this:
    PHP Code:
    $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 ;-)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jmansa View Post
    I have an php variable like this:
    PHP Code:
    $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 ;-)
    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
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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"?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jmansa View Post
    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
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot... I'm on it ;-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •