2013-05-28 50 views
-1

我有一个表单(下面的代码),其中每次单击某个选项时,都会显示一个按钮,并显示正确的值。点击它会将您带到异地的处理表单。这部分工作正常。我需要的是其中一个选项,说选项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> 
+0

我敢肯定,如果你想分享你的代码与你迄今在这个任务上的位置,人们会很乐意提供帮助。你磕磕绊绊的具体是什么? – johnkavanagh

+0

Daniel的代码正是我需要它做的。 –

回答

1

你可以只检查值,并相应地改变形式行动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"; 
    } 
} 

希望它能帮助。

+0

完美运作。感谢你的协助。 –

相关问题