I have a drop-down menu, when I select any option, the page redirects. Now I want to make the page as the selected item in the drop down. Here is my code:
HTML:
<select class="MobileDropDown">
<option value="/">Home</option>
<option value="/technology">Topics</option>
<option value="/about">About Us</option>
<option value="/vendor">Vendor Directory</option>
<option value="/popular-research">Popular White Papers</option>
</select>
Javascript:
<script type="text/javascript">
$(".MobileDropDown").change(function(){
window.location.href = $(this).val();
});
var URLMobile = window.location.href.split('/');
$(".MobileDropDown option").each(function(){
if($(this).val() == '/' + URLMobile[3]) {
$(this).attr('selected', 'selected');
}
});
</script>
I am sure this is not the best way to do this, but how would I fix this?
$('.MobileDropDown').val('/about');.var addressValue = $(this).attr("href");Gets the address of whatever was clicked.$(".MobileDropDown").val("/" + URLMobile[3]);