Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    including php in javascript function

    hi all, thanks in advance for looking...

    im trying to run a javascript function that does one thing in a div called "idGenre" when the function is called and it works okay no probs, but i all, but now i also want it to somthing else when that function is called as well. I want it to call or include a php script in another <div> called "idMain" to run the script in that div too, i did it a long time ago but have forgotton how i did it, could you please help?

    function fnGenre(genre){
    var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
    var params = "genre="+genre;
    xmlhttp.open("POST", "genre.php", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){
    document.getElementById("idGenre").innerHTML=xmlhttp.responseText;


    in here i want it to say somthing like ...
    document.getElementById("idMain").include "show.php";

    } }
    xmlhttp.send(params);
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,588
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    You can't do it.

    At least nothing like that.

    You must either put the PHP output into the <div> *AS THE PAGE IS CREATED* by your PHP page code *OR* you must use AJAX to go grab the content and use innerHTML to put it in place.

    In either case, you can't "run" the PHP script in the browser. PHP must be run on the server and must send back *ONLY* HTTP responses (usually HTML, but could be binary response) to the browser.

    I think you are badly confused.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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