• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :)
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you done so far?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither JSP nor Struts would be of any help in this whatsoever. This is something you'll need to use client-side JavaScript for.
 
Deepak Rajendran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
    Posts: 16
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.





     
    Bartender
    Posts: 1111
    Eclipse IDE Oracle VI Editor
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Bartender
    Posts: 4568
    9
    • Likes 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Ranch Hand
    Posts: 32
    Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic