我無法獲得提交表單,提交中的alert ($('#submit').val());
,因此代碼進入正確的位置,但表單未提交。JQuery函數提交()不提交表格
表單有一個其他名稱的id,提交按鈕被稱爲名稱和ID保存在一個點上,目前都設置爲提交。
任何幫助表示讚賞。
$(document).ready(function(){
// force content into cnamex
$('#submit').click(function(event){
event.preventDefault(); // prevent submit
error = '';
for (var i = 0; i < 10; i++) {
if ($('#cname' + i).length > 0) {
if ($('#cname' + i).val().length == 0) {
error = 'Names for those attending are required';
}
}
}
if (error != '') {
alert (error);
}
else {
$('#othernames').submit();
alert ($('#submit').val());
}
});
});
HTML生成PHP,這是一個版本,它沒有任何盒驗證
<form enctype="multipart/form-data" name="othernames" id="othernames" method="post" action="" target="_self">
<div class="table">
<table width="100%" border="0">
<tr>
<td colspan="3" ><input name="submit" id="submit" type="submit" value="Confirm Order" ></td>
</tr>
</table>
</div>
</form>
這是場驗證: -
<form enctype="multipart/form-data" name="othernames" id="othernames" method="post" action="" target="_self">
<div class="table">
<table width="100%" border="0"><caption>Enter names for tickets, (if any)</caption>
<tr>
<th scope="col">Name</th>
<th scope="col">Email (Optional)</th>
<th scope="col">Club</th>
</tr><tr><td><input name="cID[]" type="hidden" value="11"><input name="cname[]" id ="cname0" type="text" size="15" maxlength="20"></td>
<td><input name="cemail[]" id="cemail0" type="text" size="15" maxlength="60"></td><td><input name="cclub[]" type="text" size="15" maxlength="25" value="VRA - United Kingdom"></td></tr><tr><td><input name="cID[]" type="hidden" value="11"><input name="cname[]" id="cname1" type="text" size="15" maxlength="20"></td>
<td><input name="cemail[]" id="cemail1" type="text" size="15" maxlength="60"></td><td><input name="cclub[]" type="text" size="15" maxlength="25" value="VRA - United Kingdom"></td></tr>
<tr>
<td colspan="3" ><input name="submit" id="submit" type="submit" value="Confirm Order" ></td>
</tr>
</table>
</div>
</form>
問題使用reyaner的建議解決, 謝謝。現在JQuery的讀取和HTML使用一個提交按鈕
$(document).ready(function(){
// force content into cnamex
$('#submit').click(function(event){
error = '';
for (var i = 0; i < 10; i++) {
if ($('#cname' + i).length > 0) {
if ($('#cname' + i).val().length == 0) {
event.preventDefault(); // prevent submit
error = 'Names for those attending are required';
}
}
}
if (error != '') {
alert (error);
}
});
});
enter code here
你能告訴你的HTML –
你應該試試:'$(本).closest( '形式')得到(0).submit( );'順便說一下,ID在上下文頁面上必須是唯一的 –
而不是提交提交按鈕,然後使用'event.preventDefault();'來停止默認功能,爲什麼不簡單地使用常規按鈕並添加此功能? – Nunners