How to access iframe checkbox elements

javascript

Solution

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 :)

Problem

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. How can I 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> ```

Original source