user2514925
user2514925

Reputation: 949

Html Radio button selection

Following is my code,

$(document).ready(function () {
    $("#es").hide();
    $("#n").hide();
    $('input[type="radio"]').click(function () {
        if (this.value === "Yes")
            $("#es").show();
        else if (this.value === "No")
            $("#n").show();
    });
});

There are 2 radio buttons for yes and no.After selecting yes if select no only no option should be selected but here both buttons are getting selecte.How can i rectify this?

Upvotes: 3

Views: 149

Answers (3)

Safeer
Safeer

Reputation: 184

You need to group the radio buttons.
Give same names to the radio buttons to do so.

Upvotes: 0

Sonu Sindhu
Sonu Sindhu

Reputation: 1792

try this :

give same name both of radio button like this

<input type="radio" name="radio" value="Yes">Yes
<input type="radio" name="radio" value="no">No

Upvotes: 1

PSL
PSL

Reputation: 123739

Just provide both of them the same name. You don't need javascript to do that.

<label><input type="radio" name="group" id="es" value="Yes"/>Yes</label>
<label><input type="radio" name="group" id="n" value="No"/>No</label>

Fiddle

Upvotes: 8

Related Questions