I am trying to write a little snippet that allows a user to go to i.e. navigate to) a new url, based on a user selection in an option select control.
<script type="text/javascript">
/* <[CDATA[ */
jQuery.noConflict();
jQuery(document).ready(function(){
var id = jQuery($this).val();
var url = some_Lookup_func(id);
jQuery("#the_id").change(function () { /* how do I navigate the browser to 'url' ?*/ );
});
/* ]]> */
</script>
Note: This is not AJAX behaviour I want, I want the browser to behave as though you had clicked on a hyperlink. I have done this before, but I have forgotten how to do it. I had a look at the jQuery docs, and load() does not seem to do it - because I do not want to place the contents in the current page - I want to:
jQuery
var YourParam="sunshine";
$(document).ready(function() {
$("#goto").change(function(){
if ($(this).val()!='') {
window.location.href=$(this).val()+"?param="+YourParam;
}
});
});
HTML
<form action="whatever.shtml" method="post" enctype="multipart/form-data">
<select id="goto">
<option value="">Go somewhere...</option>
<option value="http://cnn.com/">CNN</option>
<option value="http://disney.com/">Disney</option>
<option value="http://stackoverflow.com/">stackoverflow</option>
<option value="http://ironmaiden.com/">Iron Maiden</option>
</select>
</form>
window.location.href = 'http://example.com/newlocation?param1=value1';
This also works with relative url:
window.location.href = '/newlocation?param1=value1';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With