Results 1 to 4 of 4

Thread: select parentnode from childnode checkbox

  1. #1
    Join Date
    Aug 2007
    Location
    South Africa, Durban
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default select parentnode from childnode checkbox

    Hi all,
    I'm having a problem. with a treeview, I am able to check all the checkboxes of the childitems in the treeview when a parent is checked. but now I am unsure of how, if I check a childnode, would I then check the parentnode?

    thanks in advance.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Much would depend upon your markup. A check box cannot be a parentNode of anything. A different way of looking at your markup, or a different markup may be required.

    It would be much easier to reference the 'parent' check box by its name or id.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2007
    Location
    South Africa, Durban
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ah, I see what you mean. the problem is that I'm getting the data from a database and adding it by looping through two datasets (one with parentnodes, the other with child nodes of the particular parent node) in asp.net. my javascript skills are very limited, so I am unsure whether I could somehhow use those datasets (or an equivalent) to get the name of the "child" and then register that it has that particular "parent". The main reason why I want to use javascript to try achieve this is so I don't cause a postback.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Generally, for a check box to have much use in asp and other server side code, it has a name that holds its value when the form that contains it is submitted.

    If the 'parent' check box in question is truly in a unique parentNode of these 'child' check boxes (and depending upon the organization of things, the parentNode could be the parentNode of other sets of children) , you could try:

    Code:
    parentNode.getElementsByName('the_name')[0]
    For example, let's say your child check box is represented by the variable ch, and you wanted to check the 'parent' check box with a name of master1:

    Code:
    ch.parentNode.getElementsByName('master1')[0].checked=1;
    If there isn't already a name for this check box, it would be better to give it a unique (id's must be unique on a given page) id, or use the one it has if it has one. Then the code gets much simpler, as no reference to the child or any aspects of the document's structure are needed:

    Code:
    document.getElementById('the_id').checked=1;
    There are also ways to 'walk' the structure of a form (as opposed to the actual document tree) in javascript. This might be more useful in your case, it all depends on the markup you are dealing with.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •