0

Here https://i.stack.imgur.com/by7Y0.jpg is the screenshot of attendance panel what I want to make.

I am making an attendance panel but I am not able to select single radio button in single row which is iterating in a loop and on submit value of present, absent and halfday should be stored in three different arrays. But in my case I am able to select only one radio button among all. If I change the name of radio button to three different names than I am able to select only one radio button in column but I want to select single radio button in row. Here is code.

`<tr>
<td><input type="radio"  name="present[]" required value=''></td>
<td><input type="radio"  name="absent[]" required value=''></td>
<td><input type="radio"  name="halfday[]" required value=''></td>
</tr>`
Sambhav Khare
  • 61
  • 3
  • 9
  • not sure if this would work but you could try something like this: https://jsfiddle.net/y7e85g0h/, that way each row would be unique and all the radios would go into an array (all the names must be unique though, which they may not be) – Pete May 16 '17 at 09:17

1 Answers1

0

From the Mozilla DN / HTML element reference -> input

You must use the value attribute to define the value submitted by this item. Use the checked attribute to indicate whether this item is selected by default. Radio buttons that have the same value for the name attribute are in the same "radio button group". Only one radio button in a group can be selected at a time.

Therefore, you need to set the same name and catch the value. In your case, it would look like :

<table>

<tr><td><input type="radio" name="attendance[1]" value="present" /></td>
<td><input type="radio" name="attendance[1]" value="absent" /></td>
<td><input type="radio" name="attendance[1]" value="halfday" /></td></tr>

<tr><td><input type="radio" name="attendance[2]" value="present" /></td>
<td><input type="radio" name="attendance[2]" value="absent" /></td>
<td><input type="radio" name="attendance[2]" value="halfday" /></td></tr>

</table>

Then, you have the name/id/value selected for 'attendance' and 'user' according to their name/id/value. NOTE: ID for users have to be different. You can catch and use names or IDs or both.

OldPadawan
  • 1,247
  • 3
  • 16
  • 25