Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 753
user2514925 Avatar asked May 03 '26 11:05

user2514925


1 Answers

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

like image 198
PSL Avatar answered May 06 '26 01:05

PSL