weemikey Posted July 24, 2007 Share Posted July 24, 2007 Hi all. I have a post that's quickly slipping down the list so I've done some homework and I think I'm getting close to a solution. I'm trying to make an iframe interact with the parent page it's sitting on. I have a nugget of javascript that I think is CLOSE to what I need to at least see if the two are talking. //trying some javascript $display_block .= "<script language=\"JavaScript\">\n"; //$display_block .= "alert('javascript from php');\n"; $display_block .= "alert(document.getElementById('memberName'));\n"; $display_block .="</script>"; There's a commented section that does work in that it does display the "javascript from php" alert when I load my iframe. So now I'd like to see if I can message out the content of my "memberName" div on the parent page using the document.getElementById. I know my syntax is wrong, but I don't know how this works. I'd love to hear from someone on this! If I can successfully SEE what's currently hard-coded on the parent page, then I assume I can SET that value as well. If you know how that looks (document.getElementById('memberName') = $mynewvalue???) I'd sure like to know. Thanks again, Mike Link to comment https://forums.phpfreaks.com/topic/61613-calling-javascript-in-php-question/ Share on other sites More sharing options...
per1os Posted July 24, 2007 Share Posted July 24, 2007 http://www.w3schools.com/htmldom/met_doc_getelementbyid.asp <?php $display_block .= "var x = document.getElementById('memberName');\n"; $display_block .= "alert(x.innerHTML);\n"; Should work. Link to comment https://forums.phpfreaks.com/topic/61613-calling-javascript-in-php-question/#findComment-306684 Share on other sites More sharing options...
weemikey Posted July 24, 2007 Author Share Posted July 24, 2007 Hey! Thanks for your reply. I was JUST trying that method when you posted. Doesn't seem to do anything (no alert box, no nothin'). I can see the javascript code in the frame source, but NO alert box comes up. I also tried adding some escape slashes around memberName thinking that maybe there's something to that. $display_block .= "<script language=\"JavaScript\">\n"; $display_block .= "var x = document.getElementById(\"memberName\");\n"; $display_block .= "alert(x.innerHTML);\n"; //$display_block .= "alert(\"hey mike\");\n"; $display_block .="</script>"; I'm SO close to a solution it's killing me. I don't really get the innerHTML either. I read all kinds of varying opinions on it. Why won't this work? I hate computers. Link to comment https://forums.phpfreaks.com/topic/61613-calling-javascript-in-php-question/#findComment-306711 Share on other sites More sharing options...
weemikey Posted July 24, 2007 Author Share Posted July 24, 2007 Okay, so I'm messing around and I put in this code $display_block .= "alert(x);\n"; When my php runs in the iframe I now get a message that says 'null'. Does that mean my getelementbyid is running, but there is no value returned? Anyone? Anyone? I'm dyin' here! Link to comment https://forums.phpfreaks.com/topic/61613-calling-javascript-in-php-question/#findComment-306735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.