This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drop down box selection

 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create a functionality in which if you select a user role from a dropdown box then it should populate large amounts of check boxes.

Actually, it is a web page where you assign a new user his permissions in the portal. It is a very long list of check boxex and it takes really long to complete it.

Now what I have to do is that if we select any user role from a dropdown list(any other option is also open) then it should auto populate the checkboxes defined for that role.

Any ideas how this can be done?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would just have to add an onchange event handler to the select element. You would then need a swicth stamenet of if statements that would set the checkboxes for that role.

document.formName.elementName.checked = true;

you could just create an array and loop through it to set the elements:
document.formName.elements[yourArray[i]].checked = true;

Eric
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just expanding what Eric has mentioned !!

// LOOP THROUGH EVERY FIELD IN THE FORM
for (count = 0; count < document.formname.length; count++) {

// GET CURRENT ELEMENT
var element = document.formname.elements[count];
if (element.type == "checkbox") {
element.checked = true;
}
}

Hope this helps !!
 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic