user1391118
user1391118

Reputation: 265

creating Dynamic controls in html with different names

I am creating radiobuttons in HTML .I am getting data from SQL Database.I am creating an attendence form in which there will be student name,Present Radio button ,Absent Radio button. I put the Present and Absent Radio button in a single Group,(so that only one could be clicked.The problem is that I can't create more than one radio group..My code is

<html>
<tr>
<td><?php echo $i;?></td> // Serial Number
<td> <label><?php echo $att['std_name'];?></label></td> //student name
<td><input type="radio" name="std_r[]" id="std_r[]"></td> // for present
<td><input type="radio" name="std_r[]" id="std_c[]"></td> // for absent
<td><input type="hidden" value="<?php echo $att['rollnum'];?>" > </td> //hidden field that will take roll number of student on next page

</tr>
</html>
<?php

I want that for each student there should be seperate group of radio buttons.thats why i want to create buttons with different name. Anyone who can help me with this Thanks

Upvotes: 1

Views: 1191

Answers (1)

JeffChan
JeffChan

Reputation: 188

I guess what you are asking is there are several students in the same page and each student with his own present/absent option.

You should do something like this:

<input type="radio" name="test[1]" value="present" />
<input type="radio" name="test[1]" value="absent" />

<input type="radio" name="test[2]" value="present" />
<input type="radio" name="test[2]" value="absent" />

<input type="radio" name="test[3]" value="present" />
<input type="radio" name="test[3]" value="absent" />

You may also specific the student_id as index, this will be easier for you do handle in PHP:

<input type="radio" name="test[33888]" value="present" />
<input type="radio" name="test[33888]" value="absent" />

<input type="radio" name="test[90909]" value="present" />
<input type="radio" name="test[90909]" value="absent" />

Upvotes: 1

Related Questions