SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Makavely's Avatar
    Join Date
    Jul 2004
    Location
    Romania
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax - using innerHTML from php

    Hello!

    I have a question regarding using ajax. I've create a form using ajax and it is all working ok. I've extract all the necessary data from db and display it on the page using the php function "echo". My problem is how can i alter the div's on the page FROM the php side??? For example :

    document.getElementById("mydiv").style.display="none";

    OR

    document.getElementById("hotelinfo").innerHTML="Any message";

    I want this to be called somehow from the php side!!

    Any help is much appreciated!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You can't. It's javascript. You might make your PHP script output these instructions, so they'll be sent to the browser. But I don't know if javascript contained in the output of an AJAX call is executed?

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do it from the php side? That makes things much more complex.

    Code:
    var ajax = (some ajax constructor);
    ajax.open(method, url, true);
    ajax.onreadystatechange=function () {
      if (ajax.readyState == 4 && ajax.status == 200) {
        document.getElementById("hotelinfo").innerHTML = ajax.resposeText;
      }
    }
    ajax.send(null);
    If you absolutely must use the php generated script to handle the output, look into using an ajax library that interprets scripts. (prototype.js for example)

  4. #4
    SitePoint Zealot Makavely's Avatar
    Join Date
    Jul 2004
    Location
    Romania
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know how to do it with ajax frameworks...but i was needing something that bind with what i have

  5. #5
    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)
    You could receive the script via ajax then use exec to run that code, but it would be a nightmare from security standards.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •