views:

379

answers:

2

hi, i have an radio buttonlist control. in which data are coming from DB and bidning in .cs file

now i need to write an javascript that if user select item 1 in radiobuttonlist it gets selected and again user clicks on the same item it should get deselected.

even if i have 10 items under it this thing should open that select and deselect the item clilcking on it

thank you

A: 

I think you need to use checkboxlist for that, as your current choice is not correct..

Edit:

To restrict, user can select only 1 item, use this javascript ..

 <script language="javascript" type="text/javascript">
    function UnSelect(id) {
        var frm = document.forms[0];

        for (i = 0; i < frm.elements.length; i++) {
            if (frm.elements[i].type == "checkbox") {
            if(frm.elements[i] != document.getElementById(id))
            {
                frm.elements[i].checked = false;
                }
            }
        }
    }
</script>
Muhammad Akhtar
its like user can select only one item at time[i have 10 items]. and even if he does not need to select any item that's ok. so i cannot go for chekboxlist control here
prince23
thanks for the replay Muhammad Akhtar abt the above code does not allow user to select an value at all. i need to check the checkbox items in checkbox list and the if i select another items then the first selected item should get deselect if i click the same item which i have selected it should get deselect at any time only one checkbox item should be selected. and none ofthe check box can also be selected
prince23
A: 
<input type="radio" name="foo" value="bar" onclick="Toggle(this);">

var radios = new Array;
function Toggle(radio) 
{
    if (radios[radio.name] == radio.value) 
    {
        radio.checked = false;
    }
    else 
    {
        radio.checked = true;
        radios[radio.name] = radio.value;
    }
}
Phaedrus