php - Get the value from many radiobuttons inside a table -
first create table n number of rows , each 1 of them contains 2 radio buttons. need id table row selected , option selected. mean if user selected yes or no.
<table border='1' style='width:100%'> <tr> <th>date</th> <th>time</th> <th>confirm order?</th> </tr> <tr id='56'> <td>".$date." </td> <td>".time." </td> <td>".$prog." </td> <td> <input type='radio' name='prog1' />no <input type='radio' name='prog1' />si</td> </tr> </table>
now got far getting ids rows checked. this:
var idss = []; $(':radio:checked').each(function(index) { var closesttr = $(this).closest('tr').attr('id'); idss.push($(this).closest('tr').attr('id')); }); $(function test() { $.ajax({ type: 'post', url: 'test.php', data: { idss: idss } });
how can array ids 'no' selected, , 1 array ids 'yes' selected.
i made fiddle here: https://jsfiddle.net/7w2df640/
this js:
function getarray(){ ar = {}; $(".datarow").each(function(i,o){ ar[$(o).attr("id")] = $(o).find("input[type='radio']:checked").val() }); console.log(ar); }
for html, have add class rows:
<tr class="datarow" id='56'>
and add value radio:
<input type='radio' name='prog1' checked value="no" />
in end array wanted:
object {56: "si", 57: "no"}
does make sense?
Comments
Post a Comment