• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

checkbox in jsp

 
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is that once i check the value in a check box , then i want to retain the state of that check box as "checked" whenever the user logs in again .
How can this be accomplished?

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Store the value of that checkbox in a permanent storage. A database could be an idea
 
Manish Sahni
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i am storing all the values of check boxes in the database.
However the point is how should i retain the state of the selected check box whenever i am logging in by the same id.

do i have to use any client side scripting or what , i am bit confused??


 
Sheriff
Posts: 67641
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
Just put the checked attribute on the checkboxes that should be checked.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do it in the following way:

suppose you have the checkbox



if the checkbox is checked, when you submit your form you get a request parameter c1=1 and, you tell me, you store that value in a table of a database

When you retrive the value of c1 from the database where do you put it before you invoke your jsp again? In a bean perhaps?
if it is a bean let's call it yourbean.

Set for example a request attribute with that bean in your servlet:



and look at the value of c1 in you bean when you are building your checkbox again



 
Manish Sahni
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the solution

however i also want that if the check box is unselected again then its value should not be stored in the database i.e. database should be updated again while unchecking the values..
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's quite the same.
If c1, as in the example above, is not checked, then the request parameter will be null instead of 1.
Starting from this distinction you will be able to update your database accordingly.
 
Manish Sahni
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, thanks for your help

its working fine now!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic