JQuery to go to page in select option

I am trying to write a small snippet that allows the user to go to ie) go to a new URL based on the user's selection in the selection 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 the AJAX behavior that I want, I want the browser to work as if you clicked on a hyperlink. I have done this before, but I forgot how to do it. I looked through jQuery docs and load () doesn't seem to do this because I don't want to post content on the current page - I want:

  • go to a whole new page
  • pass parameters to the url I am referring to (e.g. id of selected item
+5
source share
5 answers

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>
+6
window.location.href = 'http://example.com/newlocation?param1=value1';

URL:

window.location.href = '/newlocation?param1=value1';
+3

:

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

:

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

+1

, ( ):

  $(document).on('change','#goto', function(event){
    if ($(event.target).val()!='') {
      window.location.href=$(event.target).val();
    }
  });
+1

, window.location.href URL. , "name = value & name = value" . jQuery "", ( ).

0

All Articles