1

I'm looking for some tips and information because google isn't liking me with the results so I can' do much research. I have a select menu with some options for each module and what is supposed to happen is when the user clicks on Add and clicks Apply they are supposed to be taken to a certain page and when they click Edit they are supposed to be taken to a different page. How can I accomplish this with jQuery.

<select name="dropdown" class="fl-space">
    <option value="0">choose action...</option>
    <option value="add">Add</option>
    <option value="edit">Edit</option>
    <option value="delete">Delete</option>
</select>

1 Answer 1

3

Try this

var urlToNavigate;
$("select[name='dropdown']").change(function(){
    switch(this.value){
      case "add": 
        urlToNavigate = "addPageUrl";
        break;
      case "edit":
        urlToNavigate = "editPageUrl";
        break;
      case "delete":
       //Write delete logic here
    }
});

$("#submit").click(function(){
    if(urlToNavigate){
       location.href = urlToNavigate;
    }
});
Sign up to request clarification or add additional context in comments.

6 Comments

I forgot to add that in the template there is a submit button next to the dropdown. How does that impact the given code?
No impact, the above code simply redirects to appropriate url conditionally.
But I"m saying though your answer is if its just hte dropdown changeing and that's it. I have a submit button that the user is supposed to click after a selection from the dropdown is made.
Can I still use the load function instead?
load function will load the content from server resource into an element. What do you actually want?
|

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.