Jump to content

Calling javascript in php question


weemikey

Recommended Posts

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

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.

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!

 

;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.