my code is ignoring the checkbox option when Iterating in loop like this:
The output of is retrieved from a DB, it looks like this:
Then depending of which check box I selected then the row by the side should be selected by id and deleted.
But what happens is that doesnt matter which check box I select, always the first row is deleted. I understand that at the first iteration of the loop it just take the first id, it doest attach the id I have choosen to the row it belongs to
If so, you need to debug why checking a box doesn't submit the corresponding value. I assume there's an (unmentioned) form submission somewhere in all this?
By the way, please use code tags for all of the code in a post. I have added it for you.
In my DB I have two records with id=1 and id=5
The HTML of the jsp is like this:
When I debug after checking this:
For getting the id from the servlet I use this:
Instead of getting the id =5 I got the id =1 (because it iterates first because it is the first row at the DB)
The code at the jsp is like this:
Isaac Ferguson wrote:Yes thats right, experimenting
Sorry, but I see that as random guessing and that's never productive. Remove the id value; it's senseless. What did you think that it would accomplish?
Any other idea?
Yes. How does one properly use getParameter() to obtain the value of submitted parameters by name.
Hint: there are clues above.
Isaac Ferguson wrote:Now it works. It sends the rigth value fro the right row. But it only sends the id as it is the only value the checkbox sends to the servlet.
Not sure what you mean by this. If you mean that the other hidden inputs are not being sent then you are doing something wrong. If the hidden inputs are within the form, and the form is submitted, then they will be sent as part of the submission.
Can I add more values to the checkbos like this?
No. And please take this as constructive criticism: but you seem to have a bad habit of, when the correct way doesn't seem to work, to just try random weird things rather than trying to diagnose why the normal approach isn't working.
You can easily use the browser tools to inspect the form submission and see what is and what is not being set as part of the request. Learning to use these tools is essential and necessary.
The code above shows the value of the DB for example email = @1
But I want to update that value then I write over the old email , for ex: @1_new
Also of that I send it using a hidden button like this:
When I debug it ignores my new value it just get the old one
I also tried with this code in the jsp:
What should I do in order to overwrite the old value and send the new one?
Check the browser network section. Is the right request parameter in the request? If so, the problem is in the servlet; if not, the problem is in the HTML.