如何使从选择框中单击特定选项跳转到特定URL

How to make clicking specific option from selectbox jump to a specific URL

本文关键字:选项 URL 单击 何使 选择      更新时间:2023-09-26

我有一个表单(下面的代码),每次你点击一个选项,一个按钮出现与适当的值发送给它。单击它会将您带到一个异地处理表单。这部分工作正常。我需要的是其中一个选项,说选项3带你单独的URL。我已经为选择框使用了onchange。是否有办法做多个onchange功能?可能的目标通过选项id?如有任何意见,不胜感激。

<script>
    function clicker(frm,value,button) {
        frm.LinkId.value = value;
        if (value != "") {
            document.getElementById(button).style.display = "inline"; 
        } else {
            document.getElementById(button).style.display = "none"; 
        }
    }
</script>
<form name="PrePage" align="center" id="Prepage" method ="post" style="width:190px; text-align:center;" action= "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">
    <label for="selectbox" style="font-family: rockwell, helvetica, arial, sans-serif; font-size:1.5em"; width:190px; text-align:left;">This donation is for:</label>
    <select style="margin:0 0 30px 0; width:180px;" size="1" name="selectbox" id="selectbox" onchange="clicker(document.PrePage,document.PrePage.selectbox.options[this.selectedIndex].value,'button');" >
    <option selected value=""></option>
    <option value="value1">Option 1</option>
    <option value="value2">Option 2</option>
    <option value="value3">Option 3</option>
    <option value="value4">Option 4</option>
    <option value="value5">Option 5</option>
    </select>
    <input type="hidden" name="LinkId" id="LinkId" value="" /><input id="button" style="display:none; margin:0 0 30px 0; text-align:center;" type="image" src="images/donate_button.gif" alt="Donate" />
</form>

您可以检查值并相应地更改表单操作url ....如:

function clicker(frm,value,button) {
    if (value == 'value3')
        frm.action = "http://www.google.com";
    else
        frm.action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx";
    frm.LinkId.value = value;
    if (value != "") {
        document.getElementById(button).style.display = "inline"; 
    } else {
        document.getElementById(button).style.display = "none"; 
    }
}

希望能有所帮助。