Vikas
Vikas

Reputation: 121

How to set value on change radio button?

i have many radio buttons generated by php code:

<?php foreach($variant_details as $prodcut_variant): ?>
 <input type="radio" name="default_variant[]">
<?php endforeach;?>

it generated radion buttons like

   `<input type="radio" name="default_variant[]">`
   `<input type="radio" name="default_variant[]">`
   `<input type="radio" name="default_variant[]">`

and so on when i click on 1st radio button, its value must be value="1" and value of rest of the radio button must be value="0".

and if i uncheck and check another button then its value must be 1 and other's must be 0

Upvotes: 1

Views: 47

Answers (1)

Matheus Marzochi
Matheus Marzochi

Reputation: 44

Try this:

HTML:

<input type="radio" class="test" name="default_variant[]">

Jquery:

$(document).ready(function(){
 $(".test").click(function(){
   $(".test").val('0');
   $(this).val('1');
 });
});

Upvotes: 1

Related Questions