Forum Moderators: open
<select name='currencychoice' style='background-color:#FFFF99; width:50px;' onChange='
var queryString = "cc=" + options[selectedIndex].value;
window.location.href = window.location.href + queryString'>
The problem I have is identifying whether the page already has a querystring.
- if the? is already there, e.g. index.php?, then I don't want to add it;
- if there is already a querystring present then I need to add an & symbol before the cc, e.g. index.php?page=1&cc=1
- otherwise, if there is no querystring then I need to add in the?, e.g. index.php?cc=1
Is there an easier way of doing this and reloading the page with the selected option?
I've tried window.location.href = options[selectedIndex].value
but that seems to strip off the actual PHP page from the URL
Thanks.
[pre]
<script type="text/javascript">function relocate(select,attribName)
{
var addQuery = select.options[select.selectedIndex].value;
if(!addQuery) return; /* no selection */
var currQuery = location.search.substring(1);
location.href += (currQuery?"&":"?") + attribName+"="+addQuery;
}
</script>
</head>
<body>
<select onchange="relocate(this,'cc')">
<option value="">Choose..
<option value="1">1
<option value="2">2
<option value="3">3
</select>
</body>[/pre]