0

I have six radio button whose id is coming dynamically in foreach loop now i have to get that value outside foreach loop. If any body know solution than please help. Below is my code

<div class="person_option-block">
    <h5>No of Person</h5>
    <?php
        $no_of_persons = $this->Mdl_home->no_of_person_all();
        foreach($no_of_persons as $no_of_person){ ?>
    <label class="person_option">
        <?php echo $no_of_person['person']; ?> 
        ($ <?php echo $no_of_person['price']; ?>/person)
        <input type="radio" class="person-radio" name="no_person" id="<?php echo $no_of_person['id']; ?>" value="<?php echo $no_of_person['id']; ?>"
            onchange="get_makeup_service(<?php echo $no_of_person['person']; ?>)">

        <input type="hidden" id="person_<?php echo $no_of_person['person']; ?>" value="<?php echo $no_of_person['person']; ?> ($<?php echo $no_of_person['price']; ?>/person)">
    </label>
    <?php } ?>
</div>
<div class="pull-right">
    <a href="javascript:void(0);" class="custom-btn" id="step1-next-btn">
        Next
        <i class="fa fa-angle-double-right" aria-hidden="true"></i>
    </a>
</div>

When i click on next button the id of particular radio button should alert

$('#step1-next-btn').click(function(){ 
    $('#step1-block').hide();
    $('#step2-block').show();
}); 
Philipp Kief
  • 8,172
  • 5
  • 33
  • 43
Ruchir
  • 1
  • 1
  • 1
  • 3
  • 2
    Possible duplicate of [jQuery get value of selected radio button](https://stackoverflow.com/questions/8622336/jquery-get-value-of-selected-radio-button) – barbsan Oct 18 '18 at 08:36

2 Answers2

0

Use $('input[name=no_person]:checked').val(); expression to get the selected radio button value.

Ado
  • 637
  • 1
  • 6
  • 17
Golwin
  • 161
  • 13
0

Try Using,

$(function(){

if($("#radioID").prop("checked")) {

   var radioValue = $("#radioID").val();

}

});

Shelim
  • 141
  • 8