javascript - get the value of radio button groups using jquery -


i have php loop code generate radio button group

<?php for($i=1; $i<=10; $i++) { ?>            <div class="radio">     <label>         <input name="ans_<?php echo $i?>" value="option2" type="radio">         smallest resistance     </label> </div> <div class="radio">     <label>         <input name="ans_<?php echo $i?>" value="option2" type="radio">         largest resistance     </label> </div> <div class="radio">     <label>         <input name="ans_<?php echo $i?>" value="option2" type="radio">         have same power loss.     </label> </div> <div class="radio">     <label>         <input name="ans_<?php echo $i?>" value="option2" type="radio">         voltage , resistance values needed.     </label> </div> <?php } ?> <button id="q_next" type="button" class="btn btn-warning pull-right savebtn" name="1">save , next</button> 

when click on button name attribute value increases 1

i using name attribute make name of radio button.

now want jquery value of selected radio of each group generated on click of button???

i tried not working

$('#q_next').click(function() {    $quesid=parseint($(this).attr('name'));    $ans=$("input:[name='ans_'"+$quesid+"]").val();  }); 

try this

var radio_groups = {}; $(":radio").each(function(){     radio_groups[this.name] = true; })  for(group in radio_groups){     var selected = $(":radio[name="+group+"]:checked")     if (selected.length > 0)         alert('group : '+ group + ',value : '+ selected.val()); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -