I have an iframe on my main page, and this iframe uses php code mostly (src is php file).
At the bottom of this iframe I have this:
window.parent.document.getElementById("qry_str").value='hey';
And in the main (parent) file, I have this hidden input which I am trying to set from the iframe with js:
<input type="hidden" id="qry_str" name="qry_str">
Nothing happens when I try to set the value of this hidden input from inside the iframe. (Nothing shows up in the src code that is)! I have also tried setting the hidden inputs 'OnChange' 开发者_如何学Goevent to an alert, but it won't alert because it isn't changed I guess!
I know it finds the element because I have tried to alert the elementId and it works, the element is found!
Thankful for any help!
If the iframe is on the same domain you want to use window.top
to access the parent window.
window.top.document.getElementById("qry_str").value='hey';
View source shows the source code for the page, not a serialization of the current DOM. Use something like Firebug for that.
The onchange event won't fire because the content is being changed from a script, not from the user editing it.
Your tests show you are selecting the element, so that doesn't leave much else to go wrong except how you perform the tests to see if the code is working.
精彩评论