• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

Disable list item in ASP.Net with JavaScript

I have the following asp.net 1.1 c# code:

Payment Plan:
<asp:checkboxlist id="cblPaymentPlan" runat="server" RepeatDirection="Horizontal">
      <asp:ListItem Value="Fully Earned">Fully Earned</asp:ListItem>
      <asp:ListItem Value="Annual">Annual</asp:ListItem>
      <asp:ListItem Value="Semi Annual">Semi Annual</asp:ListItem>
      <asp:ListItem Value="Quarterly">Quarterly</asp:ListItem>
</asp:checkboxlist>

How would I disable (or not show) the 'Annual' and 'Quarterly' listitems via a javascript function?
0
russomr
Asked:
russomr
  • 4
1 Solution
 
REA_ANDREWCommented:
that coderenders simply a list of input type="checkbox" into the HTML code.

so to parse them you would do this

for(i=0;i<=document.forms[0].elements.length;i++)
{
if (document.forms[0].elements[i].type == "checkbox")
{
//Code Here
}
}

What you would need to do I think if find the naming structure, so for example your code outputs ids for the form controls like this

cblPaymentPlan_1, cblPaymentPlan_2, cblPaymentPlan_3 so using the above code you could have this

for(i=0;i<=document.forms[0].elements.length;i++)
{
if (document.forms[0].elements[i].type == "checkbox")
{
var Item = document.forms[0].elements[i];
if(Item.id == "cblPaymentPlan_1" || Item.id ==  cblPaymentPlan_2)
{
Item.checked = true;
}
}
}
0
 
REA_ANDREWCommented:
sorry missed a couple of quotation marks in that last if statement there
0
 
REA_ANDREWCommented:
Hi,

Do you require further assistance with this?

Andrew
0
 
russomrAuthor Commented:
I'm sorry, I thought I had closed this one.  Thank you for the help.
0
 
REA_ANDREWCommented:
np
:-)
0

Featured Post

Technology Partners: 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!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now