• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML table with radio buttons in every row

 
Abhishek Kumar Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 1 HTML table populated from the database. It has radio buttons in every row. At the end, there is one submit button to reflect the changes into the database if the user selects radio button in one or more rows.

How to know in which rows user has selected radio buttons.

Code is completely written in Html, Jsp and java script.

Please help me out.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably each row of the table has a primary key? Give the checkboxes all the same name, and make the values of the checkboxes the primary key for that row, and you'll know which ones have been selected.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Kumar Saxena wrote: if the user selects radio button in one or more rows.

I assume you meant checkboxes rather than radio buttons since radio buttons would mean that you can only select one of them at any time.
 
Abhishek Kumar Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I want radio buttons only. And yes, at a time , for a row, I want a user to select only one button in that group
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't mention anything about "groups" in your original post. Please explain things carefully, clearly and completely.
 
Abhishek Kumar Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for details, I am attaching the screen shot of the application.
Untitled.png
[Thumbnail for Untitled.png]
for details
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I'd replace the Pass/Fail group of radio buttons with a checkbox where checked means pass. A lot easier to deal with and would look better.

But if you can't do that, you need to generate a unique name for each group since radio buttons are grouped by name. I'd format the name using the primary key so that when the form is submitted you can parse each parameter to know which row the submitted value "belongs" to. Make the radio button values "true" and "false".
 
Abhishek Kumar Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Sir,

I tried using checkbox first, but I was not able to select one checkbox between two as there is no group defined for them.

I thought it would be easier to use radio buttons, but it seems i am not finding a way here too.

In the snapshot attached in the last post, if I'd use checkbox then how can I submit details of every checkbox to another jsp?

Please let me know.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek Kumar Saxena wrote:
I tried using checkbox first, but I was not able to select one checkbox between two as there is no group defined for them.

The point of using a check box is that there would be only one: checked for pass unchecked for fail.

In the snapshot attached in the last post, if I'd use checkbox then how can I submit details of every checkbox to another jsp?

I already explained that: the value of the box would be the primary key of the row. Only passed primary keys would be submitted.
 
Abhishek Kumar Saxena
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please provide me the sample code for that.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<label><input type="checkbox" name="hasPassed" value="213"> Passed?</label>

The 213 is an example primary key value for the row. Of course, you would substitute the actual primary key value.

There would be a control like this in each row, each with the primary key for that row, all with the same name hasPassed.

On the server, if you fetch the values of hasPassed, you will get an array of all the primary keys whose checkboxes have been checked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic