jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes HTML table with radio buttons in every row 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 "HTML table with radio buttons in every row" Watch "HTML table with radio buttons in every row" New topic
Author

HTML table with radio buttons in every row

Abhishek Kumar Saxena
Greenhorn

Joined: Aug 09, 2013
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60822
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

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

Joined: Aug 09, 2013
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60822
    
  65

You didn't mention anything about "groups" in your original post. Please explain things carefully, clearly and completely.
Abhishek Kumar Saxena
Greenhorn

Joined: Aug 09, 2013
Posts: 5
for details, I am attaching the screen shot of the application.



[Thumbnail for Untitled.png]

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

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

Joined: Aug 09, 2013
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60822
    
  65

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

Joined: Aug 09, 2013
Posts: 5
Could you please provide me the sample code for that.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

<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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTML table with radio buttons in every row
 
Similar Threads
selecting a row from table using radio buttons
selectOneRadio inside a columnEx
Dynamic forms?
Disabling form elements on a table row
passing hidden values