1

I have a program with a tree control to assign user permissions like student can access only attendance and staff can assign attendance to students and so on...

I want to validate this with javascript to see that if no checkbox in tree is selected or all nodes in a tree is deselected or left empty ..i have to throw a validation error using javascript. I have attached by design coding and js coding i have used until now.

i tried the regular checkboxes validtion and it does not produce any result. Please help me

Javascript

function AreAllSiblingsChecked(chkBox)
   {
     var parentDiv = GetParentByTagName("div", chkBox);
     var childCount = parentDiv.childNodes.length;
     for(var i=0; i<childCount; i++)
     {
        if(parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node
        {
            if(parentDiv.childNodes[i].tagName.toLowerCase() == "table")
            {
               var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
              //if any of sibling nodes are not checked, return false
              if(!prevChkBox.checked) 
              {
                return false;
              } 
            }
        }
     }
     return true;
   }
1
  • You need to provide more information. Code would help - specifically, the HTML of the tree, the javascript you have tried and any other code that you think can help us answer your question. Commented Nov 13, 2010 at 8:41

1 Answer 1

0

You could possibly set a class name of the elements you want to check and then use jquery api and selectors to get checked elements.

Have a look at the api documentation of jquery:

http://api.jquery.com/checked-selector/

http://api.jquery.com/class-selector/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.