tlsterling Posted August 6, 2006 Share Posted August 6, 2006 Hi there,I'm trying to institute remote scripting using an iframe and I'm really stumped on this error. This is my client.html file:----------------------------------------------------------------------------------------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"><html><head><title>Remote Scripting with an IFrame - complexer client page</title><meta http-equiv="pragma" content="no-cache"><script type="text/javascript">function buildQueryString(theFormName) { theForm = document.forms[theFormName]; var qs = '' for (e=0;e<theForm.elements.length;e++) { if (theForm.elements[e].name!='') { qs+=(qs=='')?'?':'&' qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value) } } return qs}function messageReciept(name, msg) { var theFormDiv = document.getElementById('theFormDiv'); theFormDiv.style.display = 'none'; var responseMessage = document.getElementById('responseMessage'); var message = '<p>Your message has been sent! Thank you.<\/p>' message += ('<p>Your Name: <\/p>' + name) message += ('<p>Your Message: <\/p>' + msg) message += '<p><a href="#" onclick="showForm(); return false;">Send another message<\/a><\/p>' responseMessage.innerHTML = message; responseMessage.style.display = 'block';}var IFrameObj; // our IFrame objectfunction callToServer(theFormName) { if (!document.createElement) {return true}; var IFrameDoc; var URL = 'server.php' + buildQueryString(theFormName); if (!IFrameObj && document.createElement) { // create the IFrame and assign a reference to the // object to our global variable IFrameObj. // this will only happen the first time // callToServer() is called var tempIFrame=document.createElement('iframe'); tempIFrame.setAttribute('id','RSIFrame'); tempIFrame.style.border='0px'; tempIFrame.style.width='0px'; tempIFrame.style.height='0px'; IFrameObj = document.body.appendChild(tempIFrame); if (document.frames) { // this is for IE5 Mac, because it will only // allow access to the document object // of the IFrame if we access it through // the document.frames array IFrameObj = document.frames['RSIFrame']; } } if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) { // we have to give NS6 a fraction of a second // to recognize the new IFrame setTimeout('callToServer("'+theFormName+'")',10); return false; } if (IFrameObj.contentDocument) { // For NS6 IFrameDoc = IFrameObj.contentDocument; } else if (IFrameObj.contentWindow) { // For IE5.5 and IE6 IFrameDoc = IFrameObj.contentWindow.document; } else if (IFrameObj.document) { // For IE5 IFrameDoc = IFrameObj.document; } else { return true; } IFrameDoc.location.replace(URL); return false;}function showForm() { var theFormDiv = document.getElementById('theFormDiv'); theFormDiv.style.display = 'block'; document.forms['emailForm'].reset(); var responseMessage = document.getElementById('responseMessage'); responseMessage.style.display = 'none';}function processState(st) { alert(st) }</script></head><body><div id="responseMessage" style="display:none"></div><div id="theFormDiv"><form name="emailForm" id="emailForm" action="server.php" onsubmit="return callToServer(this.name)">Your name:<br><input type="text" name="realname"><br>Your message:<br><textarea name="message" cols="50" rows="10"></textarea><br><br><input type="submit" value="submit"></form></div></body></html>----------------------------------------------------------------------------------------And this is what I've got for server.php:---------------------------------------------------------------------------------------<?php $username = "testName";?><script language="javascript" type="text/javascript"> parent.window.messageReciept('<?php =$username;?>' + 'ggg', '<?php echo "hhh";?>')</script>------------------------------------------------------------------------------After entering some arbitrary values into the 'Your name' and 'Your message' box and submitting, this is the output I get:-------------------------------------------------------------------------------Your message has been sent! Thank you.Your Name:gggYour Message:Send another message-----------------------------------------------------------------------I currently have the xampp (LAMP) installation set up on my machine and it seems to parse php files/commands with no trouble. Any idea why I cannot get JavaScript to recognize/parse any php??I'm really stumped, any help you can offer would be greatly appreciated, thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/16738-javascript-parsing-php/ Share on other sites More sharing options...
manmadareddy Posted August 7, 2006 Share Posted August 7, 2006 <?php//server.php?><script language="javascript" type="text/javascript"> parent.window.messageReciept('<?php echo $realname;?>', '<?php echo $message;?>')</script> Quote Link to comment https://forums.phpfreaks.com/topic/16738-javascript-parsing-php/#findComment-70483 Share on other sites More sharing options...
448191 Posted August 7, 2006 Share Posted August 7, 2006 Your php echoes javascript.Javascript CAN NOT parse php EVER.Please note the difference, it is an important one. Quote Link to comment https://forums.phpfreaks.com/topic/16738-javascript-parsing-php/#findComment-70517 Share on other sites More sharing options...
tlsterling Posted August 7, 2006 Author Share Posted August 7, 2006 My apologies for the ambiguity, I should clarify. It's not that I'm having trouble getting JavaScript to parse my PHP, but rather any PHP code in server.php located within the <script> tag does not seem to parse. Any PHP located outside said <script> tags will parse just fine. So, ideally what I'd like to happen and what I believe is supposed to happen is for the PHP to get parsed server side before it ever arrives back at the client page via the messageReciept call. So all the client.html page sees are string values as those parameters. That's not what's happening, the client page is getting nothing back when I try to incorporate a PHP command inside the <script> tag, but it will see literal text if that's all I include. I don't know why this is happening unless something's gone awry with my configuration since I've seen this exact format work just fine in the past. Any ideas?? Quote Link to comment https://forums.phpfreaks.com/topic/16738-javascript-parsing-php/#findComment-70750 Share on other sites More sharing options...
PotatoBob Posted August 9, 2006 Share Posted August 9, 2006 do you have <?php ?> tags where they are supposed to be? Quote Link to comment https://forums.phpfreaks.com/topic/16738-javascript-parsing-php/#findComment-72080 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.