Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 radio button

I'm playing with twitter bootstrap 3 and its new radio buttons and cannot seem to get which button is checked.

My buttons are like this:

    <div class="form-group">
      <label for="inputLogType" class="col-lg-2 control-label">Log type</label>
      <div class="col-lg-10">
        <div class="btn-group" data-toggle="buttons">
          <label class="btn btn-primary">
            <input type="radio" name="inputLogType" id="splunk">Splunk
          </label>
          <label class="btn btn-primary">
            <input type="radio" name="inputLogType" id="pig">PIG
          </label>
        </div>          
      </div>            
    </div>

I can get whether either button is clicked through $(".btn-group").click(), but inside there I can't get which button is clicked. I'll get the 2 buttons through jquery $("input[name='inputLogType']"), and one of them will have checked:true property. However when I do $("input[name='inputLogType']:checked"), nothing shows up.

Anyone knows what's wrong?

like image 623
Penguinator Avatar asked Oct 04 '22 08:10

Penguinator


1 Answers

Are you trying to access the :checked value in the click callback? If so, it's likely that the property hasn't been applied yet.

You can use $(event.target).find('input'); to select the targeted radio button.

like image 78
BenjaminCorey Avatar answered Oct 10 '22 07:10

BenjaminCorey