tags:

views:

485

answers:

3

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, I would like to cascade this through to all children checkboxs within the iframe as well as disable these children checkboxes.

Would really appreciate some help with this as I am not sure how to access the checkboxes within the iframe.

My iframe definition on the man page is similar to the following:

<iframe id="iframe1" src="'+URL+'" style="border:none;width:799px;height:200px;" frameborder="1" framespacing="0" marginheight="0" marginwidth="0"></iframe>

Any examples/websites would be great.

Thanks. Tony.

A: 

Not sure of your exact issue (could you provide more details?) but if the URL of the iframe src is not in the same domain as the parent, there could be cross-domain security issues that prevent manipulation via javascript, as per the same-origin policies.

Peter
+1  A: 

This might be helpful: a jquery plugin to easily access the iframe document. That is, if its not cross domain like peter said.

mkoryak
+2  A: 

Okay here is an example...

First here is the source for the iFrame contents (I called it FramePage.htm)...

<body>
    <input id="Checkbox1" type="checkbox"  name="checkbox" /> 
    <input id="Checkbox2" type="checkbox" name="checkbox"/>
    <input id="Checkbox3" type="checkbox" name="checkbox" />
</body>

Here is the source on the page that houses the iFrame...

<iframe id="frame" src="FramePage.htm"></iframe>

<input id="Button1" type="button" value="button" onclick="setData()" />

<script type="text/javascript">
    function setData()
    {
        var frame = document.getElementById('frame');

        var checkboxes = frame.contentWindow.document.getElementsByName('checkbox');

        for (var i = 0; i < checkboxes.length; i++)
        {
            checkboxes[i].checked = true;
        }
    }
</script>

Clicking the button on the parent page will select all the checkboxes with the name 'checkboxes' on the frame page.

Hope this helps :)

Chalkey
Thanks for that Chalkey - I will try it out. BTW, I also need to disable the checkbox within the iframe as well - would that just be checkboxes[i].disabled = true ?
tonsils
Off the top of my head i think it would be checkboxes[i].checked = false; I think disable would disable the control not the value... :)
Chalkey