Hi,

I have implemented an Ajax object - a div containing another ASP file which can be updated dynamically.
This ASP page has a number of checkboxes.
Is it possible to use JS (or any other tool) to check the checkbox status (i.e. like javascript's

if (field.checked)

) from the containing HTML/ASP file?

This is how I used to check the status when the checkboxes were in the containing HTML:

<img src="images/trail/ChooseAll.png" border=0 onclick="checkAll(document.<form_name>.<CheckBox_Name>)">

But now the form is in the Ajax object's ASP file, so "document" wouldn't work.

Ideas?
Thanks in advance,

Asaf

Ajax is a set of techniques to perform asynchronous requests to a server from the client side. Meaning you click check all and it sends data back to the server and waits for a response without hanging your web page and without a page post. Once you bring another page within a div you are placing that new page into the current page's DOM. So the only way to access content within the "new" page is to walk-the-dom, as it were, from the root and traverse down the tree through the containing div. If you want to keep the new page's dom separate you will want to place that document in an iFrame. Then to access it's dom you would use:

window.frames['loader_frame'].document.getElementById('foo');

.

Hello,

First of all - thanks for the time and effort - I really appreciate it!

Now, your solution seems to me like being on the right track but I have no clue how to implement it.
Therefor, let be more specific.
I have a sort of a table where each row begins with a checkbox.
I placed that table in an ASP file which is displayed in a DIV inside a "parent" page. Every change made reloads that ASP and the table without reloading the whole parent page (that's where the AJAX code kicks in).
Now, the parent page contains the control buttons - CheckAll and CheckNone and delete, move up and move down checkboxed rows buttons.
The buttons trigger a JS script which checks which checkbox is checked and acts accordingly.
Now - the buttons are in the parent page ASP but the checkboxes are in the secondary/"child" ASP page.
So how do I make a JS script tiggered by the parent page to refer to checkboxes contained in the child page - a different file all-together?

Hope I made myself clearer and, again, thanks in advance for any help.

Asaf

Unless you are actually using an iFrame there isn't a "parent" page/ "child" page. All the elements are within the same Document. Having one part update doesn't really matter as long as those updates use consistent language/definitions as the initial update. For instance, I have a div I will give an id of "dynamicDiv" and that div contains a table with checkboxes.

<div id='dynamicDiv'>
   <table><tbody>
     <tr><td><input type='checkbox' class='selectRow'></td></tr>
     <tr><td><input type='checkbox' class='selectRow'></td></tr>
     <tr><td><input type='checkbox' class='selectRow'></td></tr>
     <tr><td><input type='checkbox' class='selectRow'></td></tr>
   </tbody></table>
</div>
<div><a href='javascript:void(0)' id='checkall'>Check All</a></div>

Now when you click the check all button I'm assuming you want all of the checkboxes to become selected. Using just javascript we could do:

<script>

window.onload = function()
{
   document.getElementById("checkall").onClick = function()
   {
         var dynamicDiv = document.getElementById("dynamicDiv");
         var inputs = dynamicDiv.getElementsByTagName("input");
         for(var i = 0; i < inputs.length; i++)
         {
             if(inputs[i].className == "selectRow")
             {
                   inputs[i].checked = true;
             }//else we ignore
         }
     
   }
}
</script>

You make the code above shorter by introducing a javascript framework such as JQuery, but unless you understand the long way debugging down the road will just trip you up.

That easy, ha?
I still have a lot to learn.
THANKS!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.