我有一個問題...當用戶點擊提交 - 錯誤消息顯示,但jQuery似乎並沒有停止返回假;jQuery - 查詢不會停止後返回false使用
見下面的代碼:
function validateSubmit(){
// this will loop through each row in table
// Make sure to include jquery.js
$('tr').each(function() {
// Find first input
var input1 = $(this).find('input').eq(0);
var qty1 = input1.val();
// Find Second input
var input2 = $(this).find('input').eq(1);
var qty2 = input2.val();
// Find third input
var input3 = $(this).find('input').eq(2);
var qty3 = input3.val();
// Find select box
var selectBx = $(this).find('select');
var selectVal = selectBx.val();
if(qty1 === '' && selectVal != 'Please Select...') {
alert("You've chosen an option, but not entered a quantity to dispute, please check your inputs.");
return false;
}
if(qty1 != '' && selectVal === 'Please Select...') {
alert("You've entered a quantity, but not chosen why, please check your reasons.");
return false;
}
if (qty1 > qty2) {
alert("For one of your entries, the disputed quantity is larger than the shipped quantity.");
return false;
}
});
}
HTML那裏它被稱爲
<table>
<thead>
<tr><th>Item ID</th><th>Description</th><th>Dispute Quantity</th><th>Shipped Quantity</th><th>Ordered Quantity</th><th>Reason</th></tr>
</thead>
<tbody>
<?php
$data = mysql_query("SELECT * FROM `artran09` WHERE `invno` = '$invoiceno'") or die(mysql_error());
echo "<center>";
$i = -1;
echo "<form action=\"submitdispute.php?invno=".$invoiceno."&ordate=".$placed."\" method=\"POST\" onsubmit=\"return validateSubmit();\">";
while ($info = mysql_fetch_array($data)) {
$i += 1;
echo "<tr>";
echo "<td>".$info['item']."</td>";
echo "<td>".$info['descrip']."</td>";
echo "<td><input type=\"text\" input name=".$i." onKeyPress=\"return numbersonly(this, event)\" maxLength=\"3\"></td>";
echo "<td><input type=\"text\" value=".$info['qtyshp']." name = \"ship$i\" onKeyPress=\"return numbersonly(this, event)\" maxLength=\"3\" disabled=\"disabled\"></td>";
echo "<td><input type=\"text\" value=".$info['qtyord']." onKeyPress=\"return numbersonly(this, event)\" maxLength=\"3\" disabled=\"disabled\"></td>";
echo "<td><select name = \"reason$i\">";
echo "<option>Please Select...</option>";
echo "<option>Short/Not received</option>";
echo "<option>Damaged Goods</option>";
echo "<option>Product Not Ordered</option>";
echo "</select></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
<p><input type = "submit" value = "Dispute" name ="Submit">
</form>
任何想法?幫助大量讚賞
你能提供在客戶端的HTML輸出的樣本?另外,有沒有任何機會的JS錯誤? – Boaz
HTML輸出是一個簡單的傳遞PHP,它只是將您發送到 標題(「location:index。PHP的「); 這將會是毫無意義的展示你的是,不幸的是我的強項是在PHP,jQuery的 與其說 當我拿出了preventDefault調用,它貫穿 - 顯示錯誤消息,所以它是尋找行有過錯,但後來它沒有擊中返回false,它只是不斷提交 –
幫自己一個大忙,並從HTML/PHP刪除內嵌JavaScript的每一點,然後利用jQuery的的力量完全處理'提交'事件,從一個很好的副作用是,你的JavaScript和HTML將被分離,更容易解決。 – Sparky