• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox in jsp

 
Manish Sahni
Ranch Hand
Posts: 41
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • 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?

 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • 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
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • 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??


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, thanks for your help

its working fine now!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic