
Originally Posted by
Pullo
Hi there,
You could do this with JavaScript.
Would using JS be a solution you would consider?
If so, let me know and I'll provide you with an example.
Edit: Just to be clear, the reason I ask is because this would disable this functionality for anyone who had JS switched off.
You could always use JS and a normal form that posts to a php script which in turn redirects to the correct URL.
In any case, just a <select> without any scripting isn't going to cut it.
HTML Code:
<form id="select" action="/choose-district.php" method="get">
<select name="disctrict" id="district">
<option value="">Please choose</option>
<option value="a">A district</option>
<option value="b">B-District</option>
</select>
<input type="submit" value="Go" />
</form>
<script type="text/javascript">
document.getElementById('district').onChange = function() {
var elem = document.getElementById("district");
var selected = elem.options[elem.selectedIndex].value;
if (selected != '') {
window.location = '/' + selected + '-district';
}
}
</script>
choose-district.php
PHP Code:
<?php
if (isset($_GET['district']) && $_GET['district'] != '')
{
// district selected
$district = $_GET['district'];
header("Location: http://www.example.com/$disctrict-district");
exit;
}
// user didn't select a disctrict, redirect to the homepage
header('Location: http://ww.example.com/');
Bookmarks