?
Solved

How to access the values of a checkBoxList control from Javascript?

Posted on 2007-10-04
6
Medium Priority
?
2,316 Views
Last Modified: 2008-01-09
Hi EE,
I'd like to know how to access the values in a checkboxlist from Javascript.

The scenario:
If the user selects a value from a dropdownlist, that value should be removed from a checkboxlist present next to it.

I was able to implement this functionality in server side like this:

foreach (ListItem itm in CheckBoxList1.Items)
   if (itm.Text == DropDownList1.SelectedItem.Value)
         {
            CheckBoxList1.Items.Remove(itm.Text);
            break;
         }

It would be great if you guys can let me know how to implement the same in JavaScript.
Thanks in advance,
DreamChaser.
0
Comment
Question by:dreamchaser23
  • 3
  • 2
6 Comments
 
LVL 21

Assisted Solution

by:surajguptha
surajguptha earned 1600 total points
ID: 20017412
document.getElementById("CheckBoxList1").value
0
 
LVL 11

Assisted Solution

by:flipz
flipz earned 400 total points
ID: 20017462
//try something like this

var objDropDown = document.getElementById('DropDownList1');
var objCheckList = document.getElementById(CheckBoxList1);

strSelectedText = objDropDown[objDropDown.selectedIndex].text;

for (idx=0;idx<objCheckList.options.length;idx++) {
    if (objCheckList.options[idx].text == strSelectedText) {
        objCheckList.options[idx] = null;
    }
}
0
 

Author Comment

by:dreamchaser23
ID: 20017475
Thanks Surajguptha for your instant reply..
Actually, I want to iterate through all the items in the CheckboxList..
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Accepted Solution

by:
surajguptha earned 1600 total points
ID: 20018025
   function RemoveCheckedListItems()
    {
for (i = 0; i <= 4; i++)
{
if(document.getElementById('CheckBoxList1').rows[i].cells[0].childNodes[0].status)
{
document.getElementById('CheckBoxList1').rows[i].cells[0].removeChild(document.getElementById('CheckBoxList1').rows[i].cells[0].childNodes[0]);
document.getElementById('CheckBoxList1').rows[i].cells[0].removeChild(document.getElementById('CheckBoxList1').rows[i].cells[0].childNodes[0]);
}
}
}

This javascript removes all items within 'CheckBoxList1' that is checked. You can adapt this method to remove the item selected in drop down
0
 
LVL 21

Assisted Solution

by:surajguptha
surajguptha earned 1600 total points
ID: 20018031
You can use "i" in the below script to iterate through all the checkboxes in your checked list box

document.getElementById('CheckBoxList1').rows[i].cells[0].childNodes[0]
0
 

Author Comment

by:dreamchaser23
ID: 20130757
Thanks a lot Surajguptha..
It is working great...
Sorry for the delay in getting back to you..
Lemme grade your excellent soln :)

Many Thanks once again
DreamChaser
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question