my dog learned polymorphism*
The moose likes JSP and the fly likes How to set check/unckeck Checkbox using database value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to set check/unckeck Checkbox using database value" Watch "How to set check/unckeck Checkbox using database value" New topic
Author

How to set check/unckeck Checkbox using database value

Tushar tej
Greenhorn

Joined: Dec 26, 2008
Posts: 4
Hi everyone

I am displaying a jsp page with 3 columns 1> complaint_no, 2>user_id, 3>attend_yn.
The 3rd col. attend_yn will be checkbox.
When user logs in he will see complaints assigned to him, he will select one or more complaint_no which he will attend.

My problem is how to handle checkbox value.
The value of attend_yn='A' when checked by user and attend_yn='N' when user doesn't select any or deselect existing selected complaint.

I want to show the checkbox checked when attend_yn='A' and unchecked when attend_yn='N'.



For checkbox "attendchk" how to set value 'A' and checked as retrieved from database and value to 'N' and unchecked .

I am able to loop through complaint_no but without values of checkbox as 'A' or 'N' I cannot update database.

In AttendOKUIB.jsp I have some code as


Hope I am clear
Please advice

Tushar
[ December 26, 2008: Message edited by: Tushar tej ]
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
Check the value in the scriplet



Here i am assuming that the only value other than A would be N
If that is not the case, i hope you got the idea and can change the above code as per you data points
[ December 26, 2008: Message edited by: Sunil Kumar ]

Sunil Kumar
http://goodtoknowit.blogspot.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Better yet, step out of 2001 and avoid scriptlets by using the JSTL and EL.

For conditionals you can use the JSTL's <c:if> action, or the EL's ternary operator (?).
[ December 26, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tushar tej
Greenhorn

Joined: Dec 26, 2008
Posts: 4
Hi,
Sunil bhai thanks every much you solved my problem.

Hi,
Bear Bibeault still learning JSP and will also look into JSTL and EL.

My good luck I found this forum.
Thanks both of you.

Tushar
[ December 26, 2008: Message edited by: Tushar tej ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

If you are just learning JSP, I'd suggest learning the right and modern way of doing things right off the bat and to be sure and avoid scriptlets entirely.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Add this to your web.xml to force yourself into a scriptletless way:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set check/unckeck Checkbox using database value
 
Similar Threads
save checked value in checkbox to database
when i retrive data from access it showing empty page in tomcat
How to update a image using servlet?
My bean doesn't quite work
how do i delete multiple records