samjaiswal
asked on
Enable CheckBoxList item
I have a check box list with 7 boxes. I would also like to have one of the item to be disabled whereas the other boxes are always enabled.
I am looking for this type of logic.
CheckBoxList.item(0).enabl ed=false
CheckBoxList.item(0).check ed=true
What is the correct syntax for both of the above?
Thanks
I am looking for this type of logic.
CheckBoxList.item(0).enabl
CheckBoxList.item(0).check
What is the correct syntax for both of the above?
Thanks
ASKER
I believe this code will help me to disable checkboxlist,
Actually I need to disable one of the item from the checkboxlist not the whole checkbox.
Thanks
Actually I need to disable one of the item from the checkboxlist not the whole checkbox.
Thanks
A check box list of 7 checkboxes is actually just 7 checkboxes.
Look at the THML that is produced and post that and I can give you more specifics for your sitiuation
Look at the THML that is produced and post that and I can give you more specifics for your sitiuation
ASKER
A CheckboxList control can have multiple checkbox under single checkboxlist.
<TD style="WIDTH: 347px; HEIGHT: 191px" vAlign="top" align="left"><INPUT style="WIDTH: 76px; FONT-FAMILY: Arial; HEIGHT: 24px" onclick="checkallStrike(tr ue)"
type="button" value="Select All">
<asp:checkboxlist id="CheckBoxList1" runat="server" Font-Names="Arial">
<asp:ListItem Value="Suspension">Suspens ion</asp:L istItem>
<asp:ListItem Value="Restoration">Restor ation</asp :ListItem>
<asp:ListItem Value="DLC">DLC</asp:ListI tem>
</asp:checkboxlist>
</TD>
I can add items like Suspension,Restoration and DLC.
I want to Hide one of the listitem like DLC .
Hope this gave you a beeter idea what I'm trying to do.
<TD style="WIDTH: 347px; HEIGHT: 191px" vAlign="top" align="left"><INPUT style="WIDTH: 76px; FONT-FAMILY: Arial; HEIGHT: 24px" onclick="checkallStrike(tr
type="button" value="Select All">
<asp:checkboxlist id="CheckBoxList1" runat="server" Font-Names="Arial">
<asp:ListItem Value="Suspension">Suspens
<asp:ListItem Value="Restoration">Restor
<asp:ListItem Value="DLC">DLC</asp:ListI
</asp:checkboxlist>
</TD>
I can add items like Suspension,Restoration and DLC.
I want to Hide one of the listitem like DLC .
Hope this gave you a beeter idea what I'm trying to do.
That is what I thought you were doing. But if you look at the generated HTML you will see that it generates separte checkboxes for each <asp:ListItem> element. ASP then treats as a list, but the page itself sees separate checkboxes.
For example your code above creates this HTML:
<table id="CheckBoxList1" border="0" style="font-family:Arial;" >
<tr>
<td><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1:0" /><label for="CheckBoxList1_0">Susp ension</la bel></td>
</tr><tr>
<td><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1:1" /><label for="CheckBoxList1_1">Rest oration</l abel></td>
</tr><tr>
<td><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1:2" /><label for="CheckBoxList1_2">DLC< /label></t d>
</tr>
</table>
So assuming that you wanted to disable the first checkbox then the syntax could be one of
document.getElementById("C heckBoxLis t1_0").dis abled = true;
or
document.Form1.CheckBoxLis t1:0.disab led = true;
(Personally I would use the first syntax)
Also since you are using ASP.NET you can have the server assign this value instead of javascript (i.e. in the code-behind)
For example your code above creates this HTML:
<table id="CheckBoxList1" border="0" style="font-family:Arial;"
<tr>
<td><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1:0" /><label for="CheckBoxList1_0">Susp
</tr><tr>
<td><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1:1" /><label for="CheckBoxList1_1">Rest
</tr><tr>
<td><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1:2" /><label for="CheckBoxList1_2">DLC<
</tr>
</table>
So assuming that you wanted to disable the first checkbox then the syntax could be one of
document.getElementById("C
or
document.Form1.CheckBoxLis
(Personally I would use the first syntax)
Also since you are using ASP.NET you can have the server assign this value instead of javascript (i.e. in the code-behind)
ASKER
Thanks a lot.
Can we also make visible false ?
Can we also make visible false ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To disable a checkbox:
document.formname.checkbox
To set a checkbox to checked:
document.formname.checkbox
It is cas sensitive so make sure you enter your formname for "formname" and your checkboxname for "checkboxname" with the correct caps