0

I have a radio button select in my UI.

<div class="form-group">
    <label for="inputEditActive" class="col-lg-2 control-label"></label>
    <div class="col-lg-1">
        <input type="radio" name="radioItem" id="radioItemActive"/>
    </div>
    <div class="col-lg-1">Active</div>
    <div class="col-lg-1"></div>
    <div class="col-lg-1">
        <input type="radio" name="radioItem" id="radioItemDeactive"/>
    </div>
    <div class="col-lg-1">Deactive</div>
</div>

I want to check one of these buttons using jQuery.

So far I tried different methods that I found on the Internet, but nothing has worked properly.

Can someone please help me with this. Thank you.

Tim Groeneveld
  • 8,239
  • 2
  • 40
  • 59
jayz
  • 399
  • 1
  • 3
  • 21

1 Answers1

0

make use of .prop to check the readio button

$("#radioItemDeactive").prop('checked', true);

$(function(){
  $("#radioItemDeactive").prop('checked', true);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
     <label for="inputEditActive" class="col-lg-2 control-label"></label>
            <div class="col-lg-1">
                 <input type="radio" name="radioItem" id="radioItemActive"/>
            </div>
            <div class="col-lg-1">Active</div>
            <div class="col-lg-1"></div>
            <div class="col-lg-1">
                 <input type="radio" name="radioItem" id="radioItemDeactive"/>
            </div>
            <div class="col-lg-1">Deactive</div>
</div>
Shubham Khatri
  • 246,420
  • 52
  • 367
  • 373
  • I did exactly the same. Even-though the code runs without errors, radiobuttons remain unchecked. – jayz Oct 27 '16 at 04:36
  • are you doing this inside a `document.ready()` function or `$(function(){})` because it should happen after the component has mounted – Shubham Khatri Oct 27 '16 at 04:38