目前正在設定表單以在支付系統中創建新訂單,并且當我單擊表單中的任何按鈕時,表單會提交。有誰知道可能是什么問題?這是有問題的代碼:
<form action="scripts/php/addorder.php" method="POST">
<script src="scripts/javascript/cookies.js"></script>
<script src="scripts/javascript/addproduct.js"></script>
<label>Choose Customer: </label>
<input type="text" value="" name="name" id="name" required readonly>
<button onclick ="window.open('customertable.php','popup','width=600,height=600');">Choose</button>
<br/>
<div id="products">
<label>Products: </label>
<br/>
ID: <input type="text" value=" " name="chosenproduct0" id="chosenproduct0" required readonly>
Name: <input type="text" value=" " name="chosenproduct0name" id="chosenproduct0name" required readonly>
Price: <input type="text" value=" " name="chosenproduct0price" id="chosenproduct0price" required readonly>
Quantity: <input type="number" value="1" name="chosenproduct0quantity" id="chosenproduct0quantity" required>
<button onclick ="findproduct('chosenproduct0');">Choose Product</button>
</div>
<br/>
<label>Discount: </label>
<input type="number" placeholder="0" name="discount" id="discount" step=".01" min="0">
<label>Total: </label>
<input type="number" value="0" name="total" id="total" readonly>
<button onclick="addproduct()">Add Product</button>
<br/>
<input type="submit" id="submit" value="Create New Order" class="button"/>
</form>
uj5u.com熱心網友回復:
a 的默認型別<button>是submit. 顯式將其設定為button默認情況下不應提交表單:
<button type="button" onclick="addproduct()">Add Product</button>
uj5u.com熱心網友回復:
默認情況下,單擊按鈕時會重繪 頁面/提交表單。您可以通過將屬性添加type="button"到按鈕來解決此問題。
<button type="button" onclick="myFunction()">My button</button>
uj5u.com熱心網友回復:
防止<button>在元素中使用<Form>元素,
默認情況下,它的行為等同于<input type="submit">元素。
所以更喜歡這個
<input type="button" value="Add Product">
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/421232.html
標籤:
