Home » Php » Get value of radio button inside for loop

Get value of radio button inside for loop

Posted by: admin June 30, 2018 Leave a comment

Questions:

i am using for loop as below

<?php foreach($vtype as $vtypes) { ?>  
    <input type="radio" name="type" id="type<?php echo $vtypes['id'];?>" value="<?php echo $vtypes['id'];?>" />
<?php } ?>            

And in javascript i want to get the values of radio button clicked but everytime i click on radio button i am getting only the first value.
my javascript code

<script type="text/javascript">
    var type = document.getElementById("type").value;
</script>        
Answers: