473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Checkboxlist Validation

sheenattt
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.checked,can anyone tell me what is the command for checkboxlist?
Nov 10 '06 #1
7 16548
vssp
268 100+
<!-- This script is available free online at MediaZeal Web Design --->
<!-- http://mediazeal.com --->


<script language="JavaScript" 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(missinginfo);
return false;
}
else {
return true;
}
}

// --->
</script>



Paste this code into the body section
<form name="form" method="post" action="#" onSubmit="return 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_terms"> 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 --->
Nov 10 '06 #2
vee10
141 100+
hi,

I think this solves ur problem

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head runat="server">
  4.     <title>Untitled Page</title>
  5.     <script type="text/javascript">
  6.  function  fuc()
  7.  {
  8.  
  9. var chkList1= document.getElementById ("names");
  10. var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
  11. for(var i=0;i<arrayOfCheckBoxes.length;i++)
  12. {
  13. alert(arrayOfCheckBoxes[i].checked);
  14. }
  15. }
  16.  
  17.  
  18.  </script>
  19.  
  20. </head>
  21. <body>
  22.     <form id="form1" runat="server">
  23.  
  24.  <asp:CheckBoxList ID="names" runat="server">
  25.  
  26.      <asp:ListItem Value="1" Text="1"  ></asp:ListItem>
  27.      <asp:ListItem Value="2" Text="2" ></asp:ListItem>
  28.      <asp:ListItem Value="3" Text="3" ></asp:ListItem>
  29.      <asp:ListItem Value="4" Text="4" ></asp:ListItem>
  30.      <asp:ListItem Value="5" Text="5" ></asp:ListItem>
  31.  
  32.      </asp:CheckBoxList>
  33.  
  34.  
  35.  
  36.     </form>
  37. </body>
  38. </html>
  39.  
  40.  















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.checked,can anyone tell me what is the command for checkboxlist?
Nov 10 '06 #3
Thank you for your help but this is not working for Checkboxlist.If you can help plz tell me what shld I use for checkboxlist.
Nov 20 '06 #4
vee10
141 100+
hi,

once post ur code so that i can understand because the one i posted is for the checkboxlist only










Thank you for your help but this is not working for Checkboxlist.If you can help plz tell me what shld I use for checkboxlist.
Nov 20 '06 #5
Thanku so much for your help here am pasting my code,do help me.Thanx

Expand|Select|Wrap|Line Numbers
  1. void Page_Load()
  2.     {
  3.         Button1.Attributes.Add("onClick", "return checkbox_checker()");
  4.     }
  5.  
  6.     protected void Button1_Click1(object sender, EventArgs e)
  7.     {
  8.         //further action
  9.     }
  10. </script>
  11. <html>
  12. <head>
  13. <SCRIPT LANGUAGE="JavaScript">
  14.  
  15. function checkbox_checker()
  16. {
  17. for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
  18. {
  19. if (checkbox_form.checkbox[counter].checked)
  20. {
  21.  return true;
  22. }
  23. else
  24. {
  25. alert("Not checked");
  26. return false;
  27. }
  28. }
  29.  
  30. }
  31. </script>
  32.  
  33.  
  34. </head>
  35. <body>
  36.     <form id=checkbox_form runat="server">
  37.         <p style="text-align: left">  
  38.             <asp:CheckBoxList ID="checkbox1" runat="server">
  39.                 <asp:ListItem>sheena</asp:ListItem>
  40.                 <asp:ListItem>sheenat</asp:ListItem>
  41.                 <asp:ListItem>sheenatt</asp:ListItem>                
  42.             </asp:CheckBoxList>&nbsp;</p>
  43.         <p style="text-align: left">
  44.             <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
  45.         </p>      
  46.  
  47.     </form>
  48. </body>
  49. </html>
  50.  
Nov 21 '06 #6
vee10
141 100+
hi,
write like this
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="checkbox_checker()" />

place this script



<script type="text/javascript">

function checkbox_checker1()
{

var flag=0;
var chkList1= document.getElementById ("checkbox1");
var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
for(counter = 0; counter<arrayOfCheckBoxes.length; counter++)
{
if (arrayOfCheckBoxes[counter].checked)
{
flag=1;
}
else
{
alert("not checked");
return false;
}
}
if(flag==1)
{
alert('checked');
return true;
}
}
</script>




Thanku so much for your help here am pasting my code,do help me.Thanx

Expand|Select|Wrap|Line Numbers
  1. void Page_Load()
  2.     {
  3.         Button1.Attributes.Add("onClick", "return checkbox_checker()");
  4.     }
  5.  
  6.     protected void Button1_Click1(object sender, EventArgs e)
  7.     {
  8.         //further action
  9.     }
  10. </script>
  11. <html>
  12. <head>
  13. <SCRIPT LANGUAGE="JavaScript">
  14.  
  15. function checkbox_checker()
  16. {
  17. for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
  18. {
  19. if (checkbox_form.checkbox[counter].checked)
  20. {
  21.  return true;
  22. }
  23. else
  24. {
  25. alert("Not checked");
  26. return false;
  27. }
  28. }
  29.  
  30. }
  31. </script>
  32.  
  33.  
  34. </head>
  35. <body>
  36.     <form id=checkbox_form runat="server">
  37.         <p style="text-align: left">  
  38.             <asp:CheckBoxList ID="checkbox1" runat="server">
  39.                 <asp:ListItem>sheena</asp:ListItem>
  40.                 <asp:ListItem>sheenat</asp:ListItem>
  41.                 <asp:ListItem>sheenatt</asp:ListItem>                
  42.             </asp:CheckBoxList>&nbsp;</p>
  43.         <p style="text-align: left">
  44.             <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
  45.         </p>      
  46.  
  47.     </form>
  48. </body>
  49. </html>
  50.  
Nov 23 '06 #7
Thanks buddies..

its been so useful to us....

Happy programming.. :)
May 18 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kumar | last post by:
Hi , I am using the article code shown in below url: http://www.codeproject.com/aspnet/xmlxsltransformer.asp?df=100&forumid=118504&select=1170328 This article is very cool feature. I...
0
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all...
4
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected...
4
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
5
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
3
by: Dune | last post by:
Hi, Is there anyway to get the datavaluefield from a databound checkboxlist using javascript? If not, is there any way to associate a custom attribute with the databound checkboxlist items so...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: Patrick.O.Ige | last post by:
I have some boolean value(1 or 0 ) in a table and i want a databinded CheckBoxList to present the selected values on the page.. With CheckBox i know i can se the Checked property like so :-...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.