• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to get state of non checked checkboxes

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing a situation where i need to get states of non checked checkboxes besides checked one, as in my db all non checked will be stored as 'N' and all checked as 'Y'. Considering the fact that user can anytime make a checkbox state from on to off . I need to capture and update the db accordingly , any help would be highly solicited.
Thanks & regards,
Amit Mawkin
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit
When u do a request.getParameter("checkbox name") and get a String which corresponding to the value of the checkbox u know it is checked.
And if u get null u know it is not checked.
Chow
 
amit mawkin
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But That would be good only in cases where you know before hand , how many checkboxes are there and what are there names, Imagine a scenario where the name is a same its a checkbox group and you do not know how many checkboxes are there as say they are populated from a database. In that case you can never be sure.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot make this work if all the checkboxes have the same name. You'll need to follow some kind of standard naming convention, such as the name of the form, following by some integer i. This is how I usually code checkboxes when I don't know how many there will be (the code for the checkbox is within some loop which runs i times, and I name each checkbox FormName + i, so this way, when it comes to form submission, I can iterate through the checkboxes with a similar loop, checking which are set and which are not).
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But That would be good only in cases where you know before hand , how many checkboxes are there and what are there names, Imagine a scenario where the name is a same its a checkbox group and you do not know how many checkboxes are there as say they are populated from a database. In that case you can never be sure.


This is obviously a case for storing information in the session as the page is being generated, possibly as an ArrayList or String[]
That way when you are processing the form data you will have a list of all checkboxes.
Bill
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic