novice here, be gentle!
I am trying to incorporate some redirect rules for the below and have hit a wall.
Basically, the user selects 2 values from 2 identical dropdowns, so can be A&B or B&A.
But if the url example.com/combo/B-A, I need it to redirect to example.com/combo/A-B
Also if I am approaching it in a horrible way, open to better suggestions.
<div id="my-menu">
<div class="wrapper menu">
<form id="form-dropdown">
<select id="my-menu-1" aria-label="Combine">
<option value="a">A</option>
<option value="b">B</option>
<option value="c" selected="selected">C</option>
<option value="d">D</option>
<option value="e">E</option>
<option value="f">F</option>
<option value="g">G</option>
<option value="h">H</option>
<option value="i">I</option>
<option value="j">J</option>
<option value="k">K</option>
<option value="l">L</option></select>
<span class="spt">+</span>
<select id="my-menu-2" aria-label="Combine">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d" selected="selected">D</option>
<option value="e">E</option>
<option value="f">F</option>
<option value="g">G</option>
<option value="h">H</option>
<option value="i">I</option>
<option value="j">J</option>
<option value="k">K</option>
<option value="l">L</option></select>
<button type="submit" aria-label="Combine">Combine</button>
</form>
</div>
</div>
<script type='text/javascript'>
const form = document.getElementById('form-dropdown');
form.addEventListener('submit', (event) => {
// stop form submission
event.preventDefault();
// if valid, submit the form and redirect to combo page
var s1, s2 = "https://www.example.com/combo/" +
(s1 = document.getElementById('my-menu-1')).options[s1.selectedIndex].value + "-" +
(s2 = document.getElementById('my-menu-2')).options[s2.selectedIndex].value + "/";
//prevents usage of browser back button, but malfunctioning for some reason...cache?
window.location.replace(s2);
});
</script>