C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Videos


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...


Birthday Greetings
Learn Windows 7: Epic Browser: True Indian browser.    Epic browser is the first ever Indian browser and the first product from the Indian software company Hidden Reflex. It is also world's first Anti-Virus browser. In this resource I will give a brief description of different features of Epic.



Resources » Code Snippets » Javascript »

Validating Checkboxlist control


Posted Date: 12 Mar 2009    Resource Type: Code Snippets    Category: Javascript
Author: SanjivaniMember Level: Gold    
Rating: 1 out of 5Points: 10



Hello Friends,
As we all know we can not use checkboxlist control with required field validator control, we need to have a solution for that. I created a javascript function which will do the job of required field validator control. The JS function returns 'true' or 'false'. If checkboxlist control has got atleast one checkbox selected, the function will return 'true' else it will return 'false'

I have CheckBoxList1 control on my web page. To validate that control here is the script. You will have to change control name in the script while implementing this script.



function ValidateCheckboxList()
{

var chkitems = document.getElementById('<%= CheckBoxList1.ClientID %>');
var chkitm = chkitems.getElementsByTagName("input");
for (var i = 0; i < chkitm.length; i++) {
if (chkitm[i].checked)
{
return true;
}
}
return false;
}


To Implement, simple call this function wherever you need. I called this function on a button click event.


"
a
b
c

onclick="return ValidateCheckboxList();" />"



I have attached an aspx file, to see it running, just copy past file in any website project and run the page.



~Sanjivani




Attachments

  • Using function... (26723-122010-Default.aspx.txt)
  • Using function... (26723-122013-Default.aspx.txt)




  • Responses to the resource: "Validating Checkboxlist control"

    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Checkboxlist control  .  Validate  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Change Cursor Styles from JavaScript
    Previous Resource: No scrollbar on HTML web pages - JavaScript code
    Return to Resources
    Post New Resource
    Category: Javascript


    Post resources and earn money!
     
    More Resources



    About Us    Contact Us    Privacy Policy    Terms Of Use