C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Checkbox validation - Enforce atleast one checkbox checked


Posted Date: 22 Feb 2007    Resource Type: Code Snippets    Category: Validations

Posted By: ANITA MARY JOSEPH       Member Level: Gold
Rating:     Points: 10



Lets say you have a Datalist Control that would display multiple checkboxes with Id 'chkSubjectOfInterest'.

This Javascript code forces the user to select atleast 1 of the multiple checkboxes before proceeding to the next step. The script is set against the "onclick" attribute of the button that would be clicked to proceed.

Example:

Button1.Attributes.Add("onclick", "return ConfirmSelection(this.form);")

function ConfirmSelection(frm) 
{
for (i=0; i {
//chkSubjectOfInterest is the id of your checkbox control

if (frm.elements[i].name.indexOf('chkSubjectOfInterest') !=-1)
{
if (frm.elements[i].checked)
{
return true
}
}
}
alert('You havent selected an Item yet!')
return false
}




Responses

Author: Rumpa M    12 Jun 2008Member Level: Gold   Points : 0
thanks for the code.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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.
Previous Resource: Skip validation for calculated values displayed in a textbox
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

online optimum rewards

Contact Us    Privacy Policy    Terms Of Use