Skip to content Skip to sidebar Skip to footer

Only One Radio Button Must Be Selected At A Time

I want to select one radio button out of two radio button using Javascript here is my html code I have

Solution 1:

<div class="row">
                        <divclass="form-group"><labelclass="control-label col-sm-6">Feel Of The Cards : </label><divclass="col-sm-6"><inputid="_1234"type="radio"value="NonEmbossed"name="feel_of_card" /> Non Embossed/Smooth Finished<br><inputid="_1235"type="radio"value="Embossed"name="feel_of_card" /> Embossed/Linen Finished/Textured Cards</div></div></div>

Why do you use all instead of id value? Also do not mix CSS syntax (# for identifier) with native JS Native JS solution:

document.getElementById("_1234").checked = true;

JQuery solution:

$("#_1234").prop("checked", true);

Solution 2:

You don't need JavaScript to do that. Just give same name to both checkboxes

<divclass="row"><divclass="form-group"><labelclass="control-label col-sm-6">Feel Of The Cards : </label><divclass="col-sm-6"><inputtype="radio"value="NonEmbossed"name="feel_of_card" /> 
      Non Embossed/Smooth Finished<br /><inputtype="radio"value="Embossed"name="feel_of_card" /> 
      Embossed/Linen Finished/Textured Cards
    </div></div></div>

Post a Comment for "Only One Radio Button Must Be Selected At A Time"