I have a form with 2 button groups, I would like to be able to select an option from both groups.
Here is my code:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<fieldset id="card_type_fieldset">
<legend>Card Type</legend>
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Visa</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Master</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Amex</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Discover</button>
</div>
<input type="hidden" name="card_type" value=""/>
</div>
</fieldset>
<fieldset id="ticket_type_fieldset">
<legend>Ticket Type</legend>
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Regular</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">VIP</button>
</div>
<input type="hidden" name="ticket_type" value=""/>
</div>
</fieldset>
4
Answers
I assume you’re using buttons as options (unique or multiple), isn’t it? Please check:
Then with CSS you can make them appear to be buttons if you want that style that you’ve shown in your snippet.
Boostrap components: https://getbootstrap.com/docs/3.3/components/
Link with examples: https://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp
One option is:
Note: I moved the
hidden
input outside thediv.btn-group
to have a nice border radius on the button group.Using Bootstrap 4
Doc: Radio Buttons
In this case, I would like to use a checkbox.
you can then do some css to fit the checkbox.
your code will be
please remember that I have edited only last two buttons.
thanks
To achieve expected result, use below option of using click event and adding class
code sample – https://codepen.io/nagasai/pen/yKZZLd