I have the following select menus: JSFIDDLE. So far it all works as intended. My only issue is how can I built the URL on top of the already existing one. For example when you select the Bikes option and click on visit now it will redirect you to www.yahoo.com. What I want to do is when option from the second select box is chosen to add the extra bit of the already existing url. For example Bikes: www.yahoo.com >> Bikes-->Bike2 = www.yahoo.com/bike2. I
PS: what I am trying to avoid is adding manually the whole URL. I would like to add just the bit "/bike2" to the alredy existing URL. Can someone help?
$(document).ready(function() {
$('#basic_plan').change(function() {
$('.second-select').hide();
var an = $(this).val();
switch (an) {
case "ann":
$('.button-plans a').attr('href', "www.google.com");
$('#jeeps').show();
break;
case "bi":
$('.button-plans a').attr('href', "www.yahoo.com");
$('#bikes').show();
break;
case "tri":
$('.button-plans a').attr('href', "www.bing.com");
$('#cars').show();
break;
/* and so on */
}
});
$('.second-select').change(function() {
var an = $(this).val();
switch (an) {
case "1":
$('.button-plans a').attr('href', "www.example.com");
break;
case "2":
$('.button-plans a').attr('href', "www.bitbucket.org");
break;
case "3":
$('.button-plans a').attr('href', "www.facebook.com");
break;
}
});
});
.second-select {
margin-top: 5px;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div class="dropdown-plans">
<select id="basic_plan" name="bill_cycle">
<option value="tri">Cars</option>
<option value="bi">Bikes</option>
<option value="ann">Jeeps</option>
</select>
<br />
<select id="cars" class="second-select">
<option value="1">Car1</option>
<option value="2">Car2</option>
<option value="3">Car3</option>
</select>
<select id="bikes" class="second-select">
<option value="1">Bike1</option>
<option value="2">Bike2</option>
<option value="3">Bike3</option>
</select>
<select id="jeeps" class="second-select">
<option value="1">Jeep1</option>
<option value="2">Jeep2</option>
<option value="3">Jeep3</option>
</select>
</div>
<div class="button-plans">
<a id="abc" href="#"> Visit now </a>
</div>