2012-12-21 81 views
0

我想弄清楚如何使我的选择下拉链接重定向到该网页的选项之一。到目前为止,从研究这个我只找到一种方法来使所有的选项链接重定向到(http://stackoverflow.com/questions/10175445/load-page-on-selection-from-dropdown-form),但我只希望选项的1成为链接。此外,我需要链接工作,而无需点击提交按钮。选择下拉w /只有1个选项作为链接

EDITED使用@弗拉基米尔建议:

<form method="get" id="searchform" name="searchform" action="<?php echo home_url(); ?>/"> 
    <select name="posttype" id="selection"> 
      <option name="Product" value="Product">Legal Documents</option> 
      <option name="videos" value="videos">Legal Advice - Videos</option> 
      <option value="http://www.testing.com">An Attorney</option> 
     </select> 
<input name="s" id="s" class="s" type="text" onfocus="if(this.value=='<?php _e('');?>') this.value='';" onblur="if(this.value=='') this.value='<?php _e('');?>';" value="<?php _e('');?>" /> 

<button tabindex="2" type="submit" class="search_btn"> 
    </button> 

    <?php wp_dropdown_categories('taxonomy=videoscategory&show_option_all=All Practice Areas'); ?> 
    <?php wp_dropdown_categories('taxonomy=states&show_option_all=All U.S States'); ?> 

    </form> 

    <script type="text/javascript"> 
    $(document).ready(function() { 
     $("#selection").change(function() { 
      var curVal = $("#selection option:selected").val(); 
      if (curVal.indexOf('http://') === 0) { 
       location = $("#selection option:selected").val(); 
      } 
     }); 
    }); 
    </script> 

而且是有办法有多个值1点的选择吗?

在此先感谢。

回答

1

可以适应从Load page on selection from dropdown form

解决方案与

$(document).ready(function() { 
    $("#selection").change(function() { 
     var curVal = $("#selection option:selected").val(); 
     if (curVal.indexOf('http://') === 0) { 
      location = $("#selection option:selected").val(); 
     } 
    }); 
}); 

替换JS代码的想法是,你选中该选项的值,如果它以“http://”开头,然后设置新的位置。

+0

嗨,感谢您的回复。然而,林不知道如果我实施它是正确的,因为它不适合我,我要用我目前已经设置使用您的建议更新我的问题。 – Rich

+0

我已经创建了jsFiddle示例http://jsfiddle.net/Ap46a/,并且它已成功重定向到www.testing.com。 但我不明白你想用sungle选项的倍数值达到什么目的。无论如何,你可以用JS更改选项值 - 另一个jsFiddle示例http://jsfiddle.net/KGaps/ – Vladimir