Javascript 如何使单击特定选项从selectbox跳转到特定URL
我有一个表单(下面的代码),每次你点击一个选项,就会出现一个按钮,并将正确的值发送给它。单击它会将您带到异地处理表单。这部分很好用。我需要的是其中的一个选项,比如说选项3,让你得到一个单独的URL。我已经在为selectbox使用onchange了。有没有一种方法可以实现多个onchange函数?可能是选项id的目标?如有任何想法,将不胜感激Javascript 如何使单击特定选项从selectbox跳转到特定URL,javascript,html,forms,Javascript,Html,Forms,我有一个表单(下面的代码),每次你点击一个选项,就会出现一个按钮,并将正确的值发送给它。单击它会将您带到异地处理表单。这部分很好用。我需要的是其中的一个选项,比如说选项3,让你得到一个单独的URL。我已经在为selectbox使用onchange了。有没有一种方法可以实现多个onchange函数?可能是选项id的目标?如有任何想法,将不胜感激 <script> function clicker(frm,value,button) { frm.LinkId.va
<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>
功能点击器(frm、值、按钮){
frm.LinkId.value=值;
如果(值!=“”){
document.getElementById(按钮).style.display=“inline”;
}否则{
document.getElementById(按钮).style.display=“无”;
}
}
您只需检查该值并相应地更改表单操作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";
}
}
希望能有所帮助。我相信如果您想与目前为止完成此任务的地方共享您的代码,人们会非常乐意提供帮助。你到底在绊倒什么?丹尼尔的代码正是我需要它做的。