last day (14 days later) » 

12:25 PM
1
A: How to check if a checkbox is checked

DanielIf you want to check on server-side if a checkbox has been checked or not, you should do the following: 1. Add a value to your checkbox <input class="addToFavorite" type="checkbox" name="addToFavorite" value="addToFavourite"> Add to favorite</input> 2. Check this checkbox value on server-si...

 
no it does not work. i have added value attribute to the checkbox. but condition request.getParameter("addToFavorite") == null everytime returns true
it does not work. Really
 
Check again your checkbox name and the value from getParameter(..) call. They must match, else it'll not work. Also make sure that the name you've used for your checkbox is unique. If you've grouped multiple checkboxes under the same name , then you must use request.getParameterValues("addToFavorite")
 
please see my post. i have added FireBug screenshot
 
Please update your post with more from your server-side code. Maybe that's where the problem is. I'm quite sure that this must work.
 
yes you are right. it must work. But does not work now on me. I have added server side code before
 
12:25 PM
I see your server-side code as being : wantAddToFavorites = request.getParameter("addToFavorite").equals("on"); . Did you try the following : wantAddToFavorites = request.getParameter("addToFavorite") != null; ?
 
yeees of course. as you see on FireBug it posts it's value. And your condition to check is not null will be false
 
Hmm.. that's strange. Maybe there is a problem related to the technologies you use. Try using a hidden field, and populate that field via javascript before form gets submitted, and then get the value from that hidden field in your servlet
 
o.k what you advise me to do?
aah
o.k i thought about it. but i want to do it native
it will be hard to handle later
 
I've no other ideas. The provided code should work. Are you sure you double-checked everything?( maybe you missed to compile something...)
 
yes it based on me now. thanks a lot. i'll check everything
 
12:31 PM
try using some syso's in your servlet to make sure the flow is just the way you expect it to be.
Let me know if there's anything else I can do to help you.
 
12:47 PM
Daniel, you were right
i have posted another form. which i forget to uppend values of this input.
thanks a lot for discussing
 

last day (14 days later) »