I’ve got 3 bootstrap button groups each with drop down menus. I need to change the value of the button when user makes a selection (this part I have working) and I need to check each of the other two buttons and pull their values.
Here is a codepen
Here is my html
<section class="select-talent border-top border-bottom pt30 pb30">
<div class="container">
<div class="row" style="margin-bottom: 40px;">
<div class="col-xs-12">
<h3 class="">FILTER TALENT</h3>
</div><!-- close col -->
</div><!-- close row -->
<div class="row mt20">
<div class="col-sm-12 col-md-4 ">
<!-- Single button -->
<div class="btn-group wide dropdown">
<button type="button" class="btn btn-default btn-lg wide dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Experience Level <span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu">
<li><a data-levelID="1">Level 1 and above</a></li>
<li><a data-levelID="2">Level 2 and above</a></li>
<li><a data-levelID="3">Level 3 and above</a></li>
<li><a data-levelID="4">Level 4 and above</a></li>
<li><a data-levelID="5">Level 5</a></li>
</ul>
</div><!-- close btn-group -->
</div><!-- close col -->
<div class="col-sm-12 col-md-4">
<!-- Single button -->
<div class="btn-group wide dropdown">
<button type="button" class="btn btn-default btn-lg wide dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Salon / Location <span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu">
<li><a data-locationID="1">Location 1</a></li>
<li><a data-locationID="2">Location 2</a></li>
<li><a data-locationID="3">Location 3</a></li>
</ul>
</div><!-- close btn-group -->
</div><!-- close col -->
<div class="col-sm-12 col-md-4">
<!-- Single button -->
<div class="btn-group wide dropdown">
<button type="button" class="btn btn-default btn-lg wide dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Specialization <span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu">
<li><a data-specialtyID="1">Specialty 1</a></li>
<li><a data-specialtyID="2" >Specialty 2</a></li>
<li><a data-specialtyID="3" >Specialty 3</a></li>
<li><a data-specialtyID="4" >Specialty 4</a></li>
</ul>
</div><!-- close btn-group -->
</div><!-- close col -->
<div class="col-sm-12 col-md-12">
<p class="text-right mt10"><a class="green" href="#">RESET FILTERS <i class="fas fa-chevron-right"></i></a></p>
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
here is my js so far…
$(".dropdown-menu li a").click(function(){
//change html value of dropdown changed
$(this).parents(".dropdown").find('.btn').html($(this).text() + ' <span class="caret"></span>');
//check if Experience Level has selection
//get data-levelID of Experience Level dropdown
var levelID = $(this).parents(".dropdown").find('.btn').val($(this).data('levelID'));
//check if Location has selection
// return false or 0 if not
//get data-locationID of Experience Level dropdown
var locationID = $(this).parents(".dropdown").find('.btn').val($(this).data('locationID'));
//check if Specialization has selection
// return false or 0 if not
//get data-specialtyID of Experience Level dropdown
var specialtyID = $(this).parents(".dropdown").find('.btn').val($(this).data('specialtyID'));
// save all variables
var allSelection = "levelID: " + levelID + " locationID: " + locationID + "specialtyID: " +specialtyID ;
alert (allSelection );
});