2013-05-28 54 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

完美運作。感謝你的協助。 –

相關問題