File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to make the user select Exactly 5 options in a checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to make the user select Exactly 5 options in a checkbox" Watch "How to make the user select Exactly 5 options in a checkbox" New topic
Author

How to make the user select Exactly 5 options in a checkbox

Deepak Rajendran
Greenhorn

Joined: Aug 26, 2010
Posts: 16
HI,
I am displaying dynamic rows containing checkboxes in jsp.
I want the user to select exactly 5 checkbox. nothing more nothing less.
Please help me with this and give a sample code.
(STRICTLY NO STRUTS)
i have to use jsp servlets and dao. i must not use struts.
Please help me with a solution

THANKS IN ADVANCE :)
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
What have you done so far?


regards,
Victor M. Pereira
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

Neither JSP nor Struts would be of any help in this whatsoever. This is something you'll need to use client-side JavaScript for.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepak Rajendran
Greenhorn

Joined: Aug 26, 2010
Posts: 16
Thanks bibeault!
please explain me with a sample code, currently i am displaying dynamic rows.
for example if i am displaying 10 rows of student details the user has to select exactly 5 students among them.
please help me with this as soon as possible
Thanks in advance!!!
:-)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

Deepak Rajendran wrote:Thanks bibeault!

Helpful hint: for Westerners, it's considered rude to call by last name.

please explain me with a sample code

Nope. It's your job to write the code, not mine. You can certainly get lots of help with that code, but you're the one who does the writing.

currently i am displaying dynamic rows.

"dynamic rows" doesn't have any meaning. If you mean that you are generating these with JSP code, that's irrelevant. All that matters is what is sent to the browser.

please help me with this as soon as possible

Another helpful hint: please read EaseUp. Getting pushy will only make people not want to help you.

The overall process will include:
  • Establish change handlers on the checkboxes.
  • Use the handlers to keep a count of checked checboxes.
  • Once the count has reached 5, do whatever it is you need to do. You havent said what that is. (Disallow more checks? Start unchecking checked boxes? Electrocute the user?)
  • Deepak Rajendran
    Greenhorn

    Joined: Aug 26, 2010
    Posts: 16
    Hi Bear,

    Bear Bibeault wrote:Helpful hint: for Westerners, it's considered rude to call by last name.


    i heard that only friends will call people by their first name so i thought it will be rude to call you by your first name, anyway hereafter i will correct that.

    and speaking of my question, thank you sooo much for your help.
    I have completed that, i wrote a separate js to keep track of the checkbox count and if the count exceeds 5 i made all the other check boxes disabled.


    Bear Bibeault wrote:Nope. It's your job to write the code, not mine. You can certainly get lots of help with that code, but you're the one who does the writing.



    As i am completely new to these jsp, js and servlets, i thought it will be helpful if i have a peek at sample codes
    i have never asked you for a complete solution to my problem


    Thanks for you response!!!

    :)
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61772
        
      67

    Deepak Rajendran wrote:i heard that only friends will call people by their first name so i thought it will be rude to call you by your first name, anyway hereafter i will correct that.

    Not to turn this into an etiquette lesson, but what you say is true. But CodeRanch is casual and first name usage is ok. If you want to be more respectful, then use of the last name prefixed with Mr. (for men) or Ms. (for women) is polite. Just the use of the last name without the prefix is considered rude.

    So "bibeault" is disrespectful. "Mr. Bibeault" is formal and respectful. "Bear" is casual.

    It may seem odd, but that the custom.

    I have completed that, i wrote a separate js to keep track of the checkbox count and if the count exceeds 5 i made all the other check boxes disabled.




    Wendy Gibbons
    Bartender

    Joined: Oct 21, 2008
    Posts: 1107

    Bear Bibeault wrote:
    Deepak Rajendran wrote:Thanks bibeault!

    Helpful hint: for Westerners, it's considered rude to call by last name.


    Mr Bibeault would be good but the rule about not using first names is very old fashioned now.
    Matthew Brown
    Bartender

    Joined: Apr 06, 2010
    Posts: 4492
        
        8

    One thing I'd add: if the "only five items" is really important, then you should check it server-side as well as client-side. User's can always get around client-side checks if they want to. Checking client-side gives you better usability, but you need server-side for security.
    William Flores
    Ranch Hand

    Joined: Dec 14, 2011
    Posts: 30

    Hi Deepak Rajendran,
    I found this
    http://www.htmlgoodies.com/tutorials/forms/article.php/3479181/Checkboxes-Only-Two.htm
    I think this is similiar which you want.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61772
        
      67

    William Flores wrote:Hi Deepak Rajendran,
    I found this
    http://www.htmlgoodies.com/tutorials/forms/article.php/3479181/Checkboxes-Only-Two.htm
    I think this is similiar which you want.

    Well, he's already stated that the problem is solved, but that tutorial must be really old. It uses a lot of poor practices that I would not recommend following.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to make the user select Exactly 5 options in a checkbox