我有一個表格,如果用戶選擇值1表示提交表格,但如果他們選擇2或3他們必須從類別reason select
(那裏選擇一個值是三個選擇與類reason select
,我剛所示的一個這樣的問題,以保持代碼越短POSS)確認選擇阿賈克斯呼叫值的問題
,其被包裹在一個div的HTML稱爲audit_content
<tr>
<td>
<select name="grade" class="grade" >
<option value="1">1 - Perfect</option>
<option value="2">2 - Diagnostic</option>
<option value="3">3 - Unusable</option>
</select>
</td>
</tr>
<tr>
<td>
<select name="exposure_reason" class="reason_select" >
<option value="1">Reason One</option>
<option value="2">Reason Two</option>
<option value="3">Reason Three</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="button" class="delete_submit delete_from_audit" value=""
onClick="delete_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" />
<input type="button" class="reset_grade control_submit ie7_reset"
onclick="reset_image('<? echo $image_id; ?>','<? echo $audit_id; ?>')" value="" >
<input type="hidden" class="form_id" value="<? echo $i; ?>" >
<input type="button" name="audit_submit"
class="audit_submit audit_submit_btn ie7_submit" value="" />
</td>
</tr>
jquery的
$(document).ready(function(){
$('#audit_content').on("click", ".audit_submit", function(){
var form_id = $(this).prev('.form_id').val();
alert(form_id);
var $form = $(this);
reasonHasVal = false;
if ($form.find('select[name="grade"]').val() != "1") {
$form.find("select.reason_select").each(function() {
if ($(this).val() != "") {
reasonHasVal = true;
$.ajax({
type: "POST",
url: "ajax/image_audit.php",
dataType: "json",
data: $('#audit_form'+form_id).serialize(),
success: function(response){
$('.audited_ok_tick'+form_id).html(response);
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
return false;
}
});
if (!reasonHasVal) {
e.preventDefault();
alert("Please select a reason.");
}
}
});
});
當我點擊提交按鈕,警報與form_id
作品,但沒有別的,我知道的Ajax調用是確定的,因爲它的工作,直到我試圖添加驗證的選擇值
對於我來說缺少太多的HTML以進一步調查...... – gkalpak
需要哪些html位?整個批次約爲600行 – tatty27
在發佈的JS中引用的部分(例如'.form_id'等)。一個** [SSCCE](http://sscce.org)**或一個** [JS小提琴](http://jsfiddle.net)**也將有所幫助... – gkalpak