I am using checkboxlist in asp.net.I cant get an alert with JavaScripting when the checkboxlist is not selected.For checkbox the command is checkbox.checke d,can anyone tell me what is the command for checkboxlist?
Checkboxlist Validation
Collapse
X
-
-
<!-- This script is available free online at MediaZeal Web Design --->
<!-- http://mediazeal.com --->
<script language="JavaS cript" type="text/JavaScript">
<!--//hide script
function checkme() {
missinginfo = "";
if (!document.form .agree.checked) {
missinginfo += "\n - You must agree to the terms";
}
if (missinginfo != "") {
missinginfo ="_____________ _______________ ______\n" +
"Required information is missing: \n" +
missinginfo + "\n____________ _______________ _______" +
"\nPlease complete and resubmit.";
alert(missingin fo);
return false;
}
else {
return true;
}
}
// --->
</script>
Paste this code into the body section
<form name="form" method="post" action="#" onSubmit="retur n checkme();">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>Name: </td>
<td> <input type="text" size="20" name="name"></td>
</tr>
<tr>
<td>Email: </td>
<td> <input type="text" size="20" name="email"></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="checkbox" name="agree" value="agree_te rms"> I agree to the terms</td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Clear"></td>
</tr>
</table>
</form>
<!--
This script is available free online at MediaZeal Web Design ---> -
hi,
I think this solves ur problem
Code:<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function fuc() { var chkList1= document.getElementById ("names"); var arrayOfCheckBoxes= chkList1.getElementsByTagName("input"); for(var i=0;i<arrayOfCheckBoxes.length;i++) { alert(arrayOfCheckBoxes[i].checked); } } </script> </head> <body> <form id="form1" runat="server"> <asp:CheckBoxList ID="names" runat="server"> <asp:ListItem Value="1" Text="1" ></asp:ListItem> <asp:ListItem Value="2" Text="2" ></asp:ListItem> <asp:ListItem Value="3" Text="3" ></asp:ListItem> <asp:ListItem Value="4" Text="4" ></asp:ListItem> <asp:ListItem Value="5" Text="5" ></asp:ListItem> </asp:CheckBoxList> </form> </body> </html>
Originally posted by sheenatttI am using checkboxlist in asp.net.I cant get an alert with JavaScripting when the checkboxlist is not selected.For checkbox the command is checkbox.checke d,can anyone tell me what is the command for checkboxlist?Comment
-
Thanku so much for your help here am pasting my code,do help me.Thanx
Code:void Page_Load() { Button1.Attributes.Add("onClick", "return checkbox_checker()"); } protected void Button1_Click1(object sender, EventArgs e) { //further action } </script> <html> <head> <SCRIPT LANGUAGE="JavaScript"> function checkbox_checker() { for (counter = 0; counter < checkbox_form.checkbox.length; counter++) { if (checkbox_form.checkbox[counter].checked) { return true; } else { alert("Not checked"); return false; } } } </script> </head> <body> <form id=checkbox_form runat="server"> <p style="text-align: left"> <asp:CheckBoxList ID="checkbox1" runat="server"> <asp:ListItem>sheena</asp:ListItem> <asp:ListItem>sheenat</asp:ListItem> <asp:ListItem>sheenatt</asp:ListItem> </asp:CheckBoxList> </p> <p style="text-align: left"> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" /> </p> </form> </body> </html>
Comment
-
hi,
write like this
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick=" checkbox_checke r()" />
place this script
<script type="text/javascript">
function checkbox_checke r1()
{
var flag=0;
var chkList1= document.getEle mentById ("checkbox1" );
var arrayOfCheckBox es= chkList1.getEle mentsByTagName( "input");
for(counter = 0; counter<arrayOf CheckBoxes.leng th; counter++)
{
if (arrayOfCheckBo xes[counter].checked)
{
flag=1;
}
else
{
alert("not checked");
return false;
}
}
if(flag==1)
{
alert('checked' );
return true;
}
}
</script>
Originally posted by sheenatttThanku so much for your help here am pasting my code,do help me.Thanx
Code:void Page_Load() { Button1.Attributes.Add("onClick", "return checkbox_checker()"); } protected void Button1_Click1(object sender, EventArgs e) { //further action } </script> <html> <head> <SCRIPT LANGUAGE="JavaScript"> function checkbox_checker() { for (counter = 0; counter < checkbox_form.checkbox.length; counter++) { if (checkbox_form.checkbox[counter].checked) { return true; } else { alert("Not checked"); return false; } } } </script> </head> <body> <form id=checkbox_form runat="server"> <p style="text-align: left"> <asp:CheckBoxList ID="checkbox1" runat="server"> <asp:ListItem>sheena</asp:ListItem> <asp:ListItem>sheenat</asp:ListItem> <asp:ListItem>sheenatt</asp:ListItem> </asp:CheckBoxList> </p> <p style="text-align: left"> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" /> </p> </form> </body> </html>
Comment
-
Comment