开发者

jQuery with HTML dropdown

开发者 https://www.devze.com 2023-03-31 16:41 出处:网络
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 h

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...&开发者_StackOverflow社区lt;/option>
    <option value="add">Add</option>
    <option value="edit">Edit</option>
    <option value="delete">Delete</option>
</select>


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;
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消