CraZyDroiD
CraZyDroiD

Reputation: 7105

show a field if only a certain radio button is checked

i have two radio buttons used in my form and follow to those two radio buttons i have another field. I want to show that field if only a certain radio button is checked.otherwise by default it should be hidden.

Here i want to show effective date field only if the user checks the Scheduled Payment radio button. How can i do this?

Upvotes: 1

Views: 1808

Answers (2)

Parfait
Parfait

Reputation: 1750

$("input[name=group]").change(function () {
    if ($(this).val() == 'scheduled' && $(this).is(":checked")) {
        $("#effectiveWrapper").show();
    } else {
        $("#effectiveWrapper").hide();
    }
});

http://jsfiddle.net/wdckktz7/

AngularJS Code

<div ng-show="payment == 'scheduled'">
    <label>
         <h4><b>Effective Date*</b></h4>

    </label>
    <input type="date" />
</div>

http://jsfiddle.net/orr1p1eg/

Upvotes: 3

artm
artm

Reputation: 8584

$("input:radio[name='group']").click(function() {
    var value = $(this).val();

    if (value == 'Scheduled Payment'){
        $("#div").show();
    }
    else {
        $("#div").hide();
    }

});

and put your date input inside the div:

<div id="div">
    <label><h4><b>Effective Date*</b></h4></label>
    <input type="date" >
</div>

Upvotes: 1

Related Questions