J. Sumittanun
J. Sumittanun

Reputation: 97

How to get value from radio button bootstrap

I want get value from radio button that made by bootstrap with jquery

I try with this but not work

    $('#search-type input').on('change', function() {
   alert($('input[name=\'options\']:checked', '#search-type').val());
});
        <div class="btn-group btn-group-toggle" data-toggle="buttons" id="search-type">
            <label for="Search">Search for:&nbsp;</label>
          <label class="btn btn-secondary active">
            <input type="radio" name="options" id="option1" autocomplete="off" value="Photo" checked> Photo
          </label>
          <label class="btn btn-secondary">
            <input type="radio" name="options" id="option2" autocomplete="off" value="Video"> Video
          </label>
        </div>

Upvotes: 4

Views: 5129

Answers (1)

Sumithran
Sumithran

Reputation: 6565

Try this,

<script type="text/javascript">

    $(document).ready(function(){


        $("input[type='button']").click(function(){

            var radioValue = $("input[name='options']:checked").val();

            if(radioValue){

                alert("Your are a - " + radioValue);

            }

        });
    });

</script>

Hope helpful.

Upvotes: 4

Related Questions