tags:

views:

151

answers:

2

Hi,

Can someone please let me know that if I have a web page that consists of a checkbox (parent) and on this same web page, I also have a iframe that is sourced from another page that displays a number of records, which also has a checkbox (children) against each record, if I tick the parent checkbox and assume the iframe is hidden from the user (have a feature to show/hide iframe), can I set all children checkboxs within this hidden iframe or does the iframe need to be rendered?

I am hoping that this can be achieved without rendering the iframe contents.

Thanks, Tony.

+1  A: 

Yes, this is possible; regardless of the iframe's display state, it is still part of the DOM. (I assume you're hiding it using CSS "visibility:hidden" or -- more likely -- "display:none".)

<html>
<head>
<script type="text/javascript">
function updateFrameCheck(childName, status)
{
  var x = document.getElementById("frameThing");
  var y = x.contentDocument.getElementById("formIdFromIframe");
  y.elements[childName].checked = status;
}
</script>
</head>
<body>

<iframe src="otherpage.htm" id="frameThing"></iframe>

<input type="checkbox" onclick="updateFrameCheck(this.name, this.checked)" name="childName" />

</body>
</html>
DreadPirateShawn
I'm going to guess the iframe isn't just hidden because he said 'or does it need to be rendered', but the wording is iffy.
Ian Elliott
Based on the way it is working, my iframe is not actually rendered until the user actually expands as I have just tested it. But when I actually press on the expand button to render the iframe, my requried functionlaity works. Is there anyway I can get around this?
tonsils
"not actually rendered" -- meaning, you're dynamically adding it into the DOM upon the user expanding it? (That would explain the not-working aspect.) Or it's drawn to the page but hidden with CSS? (That's what you want, which should allow functionality while hidden.)
DreadPirateShawn
A: 

It does not matter if the Iframe is shown to the user or not. Even if you set css style as 'display: none' you can still programatically interact with the contents of the iframe.

You can set all the checkboxes and display to the user when ready.

futureelite7