Search code examples
javascriptphphtmlinnerhtml

JavaScript innerHTML include php


Why doesn't my code work?

function _(x){
    return document.getElementById(x);
}

function friends(){
    _("right").innerHTML = '<?php include_once "friendlist.php";?>';
}

Result:

<!--?php include_once "friendlist.php";?-->

How can I fix it?


Solution

  • use below code it will work

     <div id="right">
       <script>
          document.write('<?php echo include_once "include.php";?>');
       </script>
    </div>
    

    or i test below code also it will work

     <body>
         <div id ="right" >
    
         </div>
      </body>
    
      <script>
        function friends(){
         var x=document.getElementById("right");
         x.innerHTML = '<?php include_once "include.php";?>';
         }      
        friends();    
     </script>