-3

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

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

I want to make a separate function in which a one radio button will be selected out of two radio button?

what is the possible way to write javascript function ?

svarog
  • 9,477
  • 4
  • 61
  • 77

2 Answers2

1

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

<div class="row">
  <div class="form-group">
    <label class="control-label col-sm-6">Feel Of The Cards : </label>
    <div class="col-sm-6">
      <input type="radio" value="NonEmbossed" name="feel_of_card" /> 
      Non Embossed/Smooth Finished<br />
      <input type="radio" value="Embossed" name="feel_of_card" /> 
      Embossed/Linen Finished/Textured Cards
    </div>
  </div>
</div>
Sagar V
  • 12,158
  • 7
  • 41
  • 68
1
<div class="row">
                        <div class="form-group">
                        <label class="control-label col-sm-6">Feel Of The Cards : </label>
                        <div class="col-sm-6">
                        <input id="_1234"  type="radio" value="NonEmbossed" name="feel_of_card" /> Non Embossed/Smooth Finished<br>
                        <input id="_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);

VK.Anup
  • 33
  • 8