开发者

Is it possible to create a dropdown list (not menu) of hyperlinks

开发者 https://www.devze.com 2023-02-21 14:41 出处:网络
nyone know if its possible to create a dropdown list of hyperlinks. So besides the hyperlink replacing the text field, there\'s also a value for each item in the list. Wondering if there\'s any jquery

nyone know if its possible to create a dropdown list of hyperlinks. So besides the hyperlink replacing the text field, there's also a value for each item in the list. Wondering if there's any jquery or other client side script that will let me turn my list item names into links. Using MVC2 as serverside. Ultimately clicking on any link in the dropdown list will open a new window, this is so people can not only select a product variant but also view the details of the selected product variant in a pop-up window before submitting the form.

The hyperlink would be constructed from the items value, which is the productID and the URL that will open in a new window will just pass that as a perimeter to an action method.

Currently using this script to do the job, but I have to employ a button next to the drop down list and its kinda ugly and confusing 开发者_开发技巧as you won't write too much on a button.

  function JumpToIt1(frm) {
        var newPage = frm.droppa.options[frm.droppa.selectedIndex].value
        if (newPage != "None") {
            window.open("http://mydomain.com/category/" + newPage, "mywindow", "menubar=1,resizable=1,width=550,height=250");
        }
    }


$(function() {

  $('#dropdownId').change(function() {
    var page = $(this).val();
    if (page != "None") {
        window.open("http://mydomain.com/category/" + page, "mywindow", "menubar=1,resizable=1,width=550,height=250");
    }
  });  

});

Be aware though that the new window will only open when the user selects a different value from the currently selected one. So if you remove your button the user will have no way of opening the window twice in a row without first selecting a different value.


You can have a dropdown with an onChange handler that causes it to run JavaScript whenever the dropdown changes (ie someone selects something out of the list). I think that will do what you want.


try this:

function openPopup(newPage){

        if (newPage != "None") {
            window.open("http://mydomain.com/category/" + newPage, "mywindow", "menubar=1,resizable=1,width=550,height=250");
        }

}
    $(#dropdownId").find("option").each(function(){
    var $Obj= $(this);
  $(this).text("<a href='javascript:void(0);' onclick='openPopup("+$Obj.val()+")'>" + $Obj.text() +"</a>");
    });
0

精彩评论

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