DiniZx DiniZx - 1 year ago 67
Javascript Question

How to avoid radio button deselected automatically.

There are two radio button. when select any radio button its automatically deselected.

Following are the snippet which is not working properly.

var payment_mode =$(this).attr('ownid');

var type = typeof payment_mode;
if(payment_mode == 'undefined' | payment_mode == null){
alert("Please select payment method");
if(payment_mode == "paypal")
$('input:radio[name="payment_mode"][ownid="paypal"]').attr('checked', true);

return false;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" id="frm_choose_plan" name="frm_choose_plan">
<label>Choose Payment method:</label>
<input type="radio" class="radio_pmt" ownid="paypal" name="payment_mode" value="Paypal">Paypal
<input type="radio" class="radio_pmt" ownid="braintree" name="payment_mode" value="braintree" id="credit_cardpmt">Credit card

Answer Source

Remove the return false; line and your code will work. It is deselecting because you are preventing the default action of radio button

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download