1

alt text

I need to implement a drop down menu like the one in the image. I know how to accomplish something like this when there is no 'go' button but how would I do this with the the 'go' button? Is there a way to allow the user to select a link but not trigger it unless the user clicks the go button? Is there a jquery plugin or something for this kind of behavior?

Im not very good with JS, so sample snippets to illustrate your suggestions will go a long way to helping me understand - thanks!

2 Answers 2

1

You can prevent the default behavior of the links, like this:

$(document).ready(function() {

  $("#menu a").click(function(event) {
    event.preventDefault();
  });  

});

So the user won't be redirected when choosing the link, but won't break that behavior in case he wants to open it in a new tab/window, which is cool.

And for redirecting the user when he clicks, you can just attach an event to the GO button which finds the selected a, takes its href, and set the current location to it's value.

Sign up to request clarification or add additional context in comments.

3 Comments

How would I go about finding the currently selected link when the user clicks 'go'?
@Thomas: Add "selected" id to selected list item (when selecting) and then $("#selected").attr("href") will give you correct link.
I agree with Im0rtality approach (Y)
1

You could do something like this:

$("#menu a").click(function(event) {
    $("#menu a").removeClass('selected');
    $(this).addClass('selected');
    return false;
}); 

Then:

$("#buttonid").click(function(event) {
    window.location.href = $("#menu a.selected").attr('href');
}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.