delacoora
delacoora

Reputation: 13

jquery select value based radio conditional disable

when a user select as type1 he can only choose radio button of value=card, cod option should be disable.

<select id="ctype" name="type">
                <option value="1">type1</option>
                <option value="2">type2</option>
                <option value="3">type3</option>
                <option value="4">Type4</option>
            </select>


            <input type="radio" class="payment" name="paymentid" value="card"/>card
            <input type="radio" class="payment" name="paymentid" value="cod"/>cod

     $("#ctype").on('change', function(){
         this.value !== "1"
         $('.payment').prop({disabled: this.value === "1", checked: false});
     })
     .change();
});

how do i allow only card radio button and disable the cod radio option when user select type1.

Upvotes: 0

Views: 36

Answers (1)

j08691
j08691

Reputation: 207900

Like this

$('#ctype').on('change', function() {
  $('.payment[value="cod"]').prop({
    disabled: this.value === "1",
    checked: false
  });
}).change();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="ctype" name="type">
  <option value="1">type1</option>
  <option value="2">type2</option>
  <option value="3">type3</option>
  <option value="4">Type4</option>
</select>


<input type="radio" class="payment" name="paymentid" value="card" />card
<input type="radio" class="payment" name="paymentid" value="cod" />cod

Upvotes: 1

Related Questions