Created
November 14, 2013 04:13
-
-
Save EricYue2012/7461232 to your computer and use it in GitHub Desktop.
Update URL query string and redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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