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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.