tags:

views:

38

answers:

4

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:

  1. go to an entirely new page
  2. pass parameters to the url that I am navigating to (e.g. the id of the selected item
+1  A: 
window.location.href = 'http://example.com/newlocation?param1=value1';

This also works with relative url:

window.location.href = '/newlocation?param1=value1';
Darin Dimitrov
A: 

To simply reload the page, set the window.location.href to your URL. To pass parameters, build a string of "name=value&name=value" and tack it onto the end. jQuery provides a "serialize" method that makes it easy to do that (as if it were hard to begin with).

Pointy
+1  A: 

This:

jQuery("#the_id").change(function () {
  document.location.href = 'url here' + $(this).val();
};

More Info:

http://javascript.gakaa.com/document-location.aspx

Sarfraz
A: 

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/"&gt;CNN&lt;/option&gt;
    <option value="http://disney.com/"&gt;Disney&lt;/option&gt;
    <option value="http://stackoverflow.com/"&gt;stackoverflow&lt;/option&gt;
    <option value="http://ironmaiden.com/"&gt;Iron Maiden</option>
  </select>
</form>
Gert G