Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to validate a checkbox controls.....I have made validation for textbox ... is there any dll files to be used....
Posted

You can simply do this with javascript

I assume you have several checkboxes on your form and you want to check whether atleast one checkbox is checked or not on button click

add the following code in your source. just remember 'myform' is the id of the form of your page

<input type="checkbox" name="check_list" value="1" />check 1<br />
        <input type="checkbox" name="check_list" value="2" />check 2<br />
        <input type="checkbox" name="check_list" value="3" />check 3<br />
        <input type="checkbox" name="check_list" value="4" />check 4<br />
        <input type="checkbox" name="check_list" value="5" />check 5<br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ValidateChecks(document.myform.check_list)"/>


and add the following function of javascript

function ValidateChecks(chk)
    {
        var flag=0;
        for (i = 0; i < chk.length; i++)
        {
            if(chk[i].checked==true)
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            alert("You Did not select any checkbox.");
        }
     }


I hope you find this helpful
 
Share this answer
 
What type of validation you want to have?

Checkbox has two option : true / false.

You cant make it required as false is an option for checkbox. :(
 
Share this answer
 
You just refuse to buy a book, don't you ?

You could write a custom validator that iterates over your checkboxes and enforces your condition ( I assume you want at least one selected ). ALL validation should also be checked on the server, worst case is that some things end up requiring post back to validate.

Is this still for the id card site that you're writing for someone who thinks you know how to write code, or rather, that your boss hires real programmers ? Do you have any idea how hard it will be for anyone to ever work on your code, because you don't follow any sort of coding standard ? Or how shocked any real developer would be to see your database code in your presentation layer ? Or your lack of understanding of basic database security ? Seriously, do you want to become a programmer, or just ride out this job until even your boss ( who we have established is a moron ) decides that he can do better and fires you ? Asking the sort of questions you're asking, will perhaps get you code you can cobble together, but it won't teach you the basics of programming.

You need to quit this joke of a job, tell the client that your boss is a liar and a thief, and get into some sort of course, if you really want to be a programmer.
 
Share this answer
 
IF I NOT SELECTED ANY CHECKBOX....
 
Share this answer
 
*sigh* I have asked you so often to edit your post, not add 'answers' that are really more questions. Yes, that article does show how to do this. The real problem is that your project will consist of code you copied off the web. Do you take the time to understand each article ? Do you play with the code, read up on it, etc ? Do you pay attention to the coding standards each article writer uses, and consider how you may use them ? These things may help you learn, even if you're learning everything backwards because you've chosen to accept a job when you have no idea how to code, and your boss has decided that is fine by him.

You may think I am attacking you, but I am really trying to make you both see how immoral what you are doing is, but also to see what steps you need to take if you want to become a real programmer at some point.
 
Share this answer
 
I UNABLE TO EXPLAIN DEAR FRIEND.. SORRY IF I SAID ANYTHING WRONG... AS I NEWLY JOINED MY BOSS WANTS TO DO IT .. k.. lEAVE IT THE PROJECT.. I SEARCH ARTICLES ON NET AND TRY TO DO IT AS OWN...


I GOT A LINK FOR SAVING A LABEL ON iMAGE ...

http://www.codeproject.com/KB/GDI-plus/watermark.aspx

KEEP GOIN ON..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900