-2

This is so basic, but I cant get it.

On a donation form, people select either pre-set amountoptions or 'other'. If they choose 'other', the 'other' radio button must be activated even if a pre-set was selected.

HTML:

<label>
<input type="radio" name="x_ccPayment" class="required" title="*" 
    value="120" data-payment="once" />
$120</label>


<label>
<input type="radio" name="x_ccPayment" class="required" title="*"
    value="50" data-payment="once" />
$50</label>

<label>
<input type="radio" name="x_ccPayment" class="required" title="*"
    value="-99" data-payment="once" />
Other:</label>
<input type="text" name="x_ccPayment_other" id="other_once" style="width: 100px;" value="" onKeyUp="checkNumericInput(this)"  data-payment="once" class="form-control" />

JQUERY:

 $("#other_once").keyup(function(){
    var other_once =  $("#other_once").val();
    if (other_once !=='') {
        $("input[name=x_ccPayment]").removeAttr('checked'); // deselect other options
        $("input[name=x_ccPayment][data-payment=once][value=-99]").attr('checked','checked');  /auto-select the 'other' radio
    }

 });

when I look at the Dev tools, i see the radio is checked correctly, but this does not show on the screen.

kneidels
  • 956
  • 6
  • 29
  • 55

1 Answers1

1

Don't use .removeAttr() and .attr() for the checked property. Use .prop():

$("input[name=x_ccPayment]").prop('checked',false); // deselect other options
$("input[name=x_ccPayment][data-payment=once][value=-99]").prop('checked',true);  
j08691
  • 204,283
  • 31
  • 260
  • 272