我是新來的表單和Javascript,所以請原諒。使用javascript提交不同值的表格
我有一個看起來像這樣的形式:
<form method="post" action="control" name="myform">
<input type="submit" name="Name" value="Do A"/>
<input type="submit" name="Name" value="Do B" />
<input type="submit" name="Name" value="Do C" />
<input type="submit" name="Name" value="Close" />
</form>
我需要這樣有兩個按鈕和形式使用JavaScript依賴於某些外部條件提交給改變這一點,所以我希望它看起來像這樣:
<form method="post" action="control" name="myform">
<script>
function submitForm(form){
if(someConditionA){
submit the form so that the script performs same action as if the button Do A had been clicked
} if (someConditionB){
submit the form so that the script performs same action as if the button Do B had been clicked
} if (someConditionC){
submit the form so that the script performs same action as if the button Do C had been clicked
}
}
function closeForm(form){
window.close();
}
</script>
<button name="doAction" onClick="SubmitForm(this.form)">Do Action<\button>
<button name="close" onClick="SubmitForm(this.form)">Close<\button>
</form>
我該如何實現函數submitForm?
感謝
對於初學者來說,在你的事件處理函數中有'SubmitForm',但函數名爲'submitForm'。 'this.form'不存在。您的提交按鈕應該有不同的名稱來區分它們。 – 2012-08-10 14:42:25
對不起,錯字。這些按鈕必須具有相同的名稱,以便cgi腳本可以處理它 – Tom 2012-08-10 14:46:45
我不明白「提交表單以便執行與上面的操作相同的操作」的意思。 – 2012-08-10 14:46:52