Skip to content

Instantly share code, notes, and snippets.

@EricYue2012
Created November 14, 2013 04:13
Show Gist options
  • Save EricYue2012/7461232 to your computer and use it in GitHub Desktop.
Save EricYue2012/7461232 to your computer and use it in GitHub Desktop.
Update URL query string and redirect
//HTML
<select id="year_selector" onchange="redirectTo(this)">
<option value="">Select Year</option>
<option value="2014">2014</option><option value="2013">2013</option>
</select>
//Javascript
function redirectTo(sel) {
var current_url = document.URL;
var param_year = sel.options[sel.selectedIndex].value;
var new_url = current_url.replace(/year=\d{4}/g, 'year='+param_year);
window.location = new_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment