By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

I need to mix PHP and JS to do a task involving DHTML

P: 14
Expand|Select|Wrap|Line Numbers
  1. function callPHPHead(s, m, y, d) {
  2.   var xhttp = new XMLHttpRequest();
  3.   xhttp.onreadystatechange = function() {
  4.     if (xhttp.readyState == 4 && xhttp.status == 200) {
  5.      document.getElementById("idMo").style.display = "block";
  6.      document.getElementById("idMo").innerHTML = xhttp.responseText;
  7.     }
  8.   };
  9.   var c = "head.php?m="+m+"&y="+y+"&d="+d;
  10.   xhttp.open("GET", c, true);
  11.   xhttp.send();
  12.   callPHPScript(s+".php",m,y,d);
  13. }
  14.  
  15. function callPHPScript(url, m, y, d) {
  16.   var xhttp = new XMLHttpRequest();
  17.   xhttp.onreadystatechange = function() {
  18.     if (xhttp.readyState == 4 && xhttp.status == 200) {
  19.      document.getElementById("showMo").innerHTML = xhttp.responseText;
  20.     }
  21.   };
  22.   var c = url+"?m="+m+"&y="+y+"&d="+d;
  23.   xhttp.open("GET", c, true);
  24.   xhttp.send();
  25. }
  26. </head>
  27. <body onload='callPHPHead("month",<? echo $m . "," . $Y . "," . $d; ?>)'>
  28.  
  29. <div id="idMo" class="w3-modal">
  30. <p id="showMo"></p>
  31. </div>
  32.  
  33. </body>
  34. </html>
I get a weird error where I'm missing a bracket or one too many and there's no code there. It's on line one, and two. where I have <html>, <head> respectively.
Apr 16 '16 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the first thing you need to understand is that PHP only runs on the server. i.e. you need to make a new request to get the PHP working.
Apr 17 '16 #2

P: 14
Yea, I got the JS to get it going. I knew that about PHP. I got to having the modal pop out. That was pretty cool. Now I'm using another JS func to rerun the page. Going to see what I can do today.
Apr 17 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.