0

I am trying to create a navigation shortcut on a web page using a drop down list.

I have the basic list:

<form>
 <label for="xx">Select a Location</label>
 <select name="xx" id="xx">
 <option selected>Please select one</option>
 <option value="http://www.google.com/">Google</option>
 <option value="http://www.search.com/">Search.com</option>
 <option value="http://www.dogpile.com/">Dogpile</option>
 </select>
 <input type="submit" value="Go" />
</form>

However, when implemented it just sputters and doesn't go anywhere. Ideally I would like to be able to skip the Go button and just have it jump to the desired page after you select the link from the list.

I would appreciate some guidance on the next steps.

Thanks.

forrest
  • 10,570
  • 25
  • 70
  • 132

2 Answers2

1
$("#xx").change(function() {
    window.location.assign($(this).val());
});

Fiddle here

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • do you know if it is better to use `replace` of `assign`? (I've checked and found the `replace` on this thread: http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery) – JMax Nov 17 '11 at 15:51
  • 1
    It depends on how you want it to work. `replace` means that when the user goes to the next page, it will replace the current on in their browser history. Using `assign` means when they click the back button, they will return to the page which sent them. – Rory McCrossan Nov 17 '11 at 15:52
1

You can try this:

$("#xx").change( function () {
  // simulates similar behavior as an HTTP redirect
  window.location.replace($(this).val());
});

You are then using the .change() API of jquery and finding the value of the select to redirect to another page.

JMax
  • 26,109
  • 12
  • 69
  • 88
  • Hi JMax, sorry for the delay in responding. I had a massive interruption to this project. Now that Im a back, I have tried this but it doesn't take you to a new page. Take a look at this page: http://www.flowerwood.com/locations/loxley_alabama. If you select a new site from the drop down and click go, it simply refreshes the page. – forrest Nov 25 '11 at 17:26
  • Hi JMax, it is working well now, because I got a little more inputer. I add the document load part and removed a pair of parenthesis. Thanks for the help. – forrest Nov 25 '11 at 21:42