基本的な検証を行うために、チェックボックスがオンになっているかどうかを確認できる必要があります。問題: これを生成する PHP にアクセスできません。クラスが追加されていないか、ほとんどのフォームにある基本的な checked=checked はありません。チェックボックスをターゲットにする最も簡単な方法は何ですか?
http://www.inpresence.in/event-registration?ee=4
編集:フリークアウト!! これがコードです。チェックボックスをターゲットにするだけで、他のすべてが機能しています。jquery の :checked メソッドは、そこにないチェックボックス内で checked=checked を使用します。
$(document).ready(function(){
//when the submit button is clicked...
$("input.btn_event_form_submit").click(function(){
//find the value of the drop down with one evening or four evenings
var priceOption = $("#price_option-4").val();
//match a string ending with "one evening" as the first numbers will be randomly generated by php
var oneEvening = /^\d{2}\|One Evening$/.test(priceOption);
//match a string ending with "four evenings" as the first numbers will be randomly generated by php
var fourEvenings = /^\d{2}\|Four Evenings$/.test(priceOption);
//HOW DO I GET THE CHECKED BOXES?!
var checkedBoxCount = $('#dates-1351733097 .valid').is(':checked').length;
//if one evening is selected make sure the checked boxes count does in fact equal one
if(oneEvening && checkedBoxCount != 1){
//if it doesn't alert the user and return false
alert('You must select one date');
return false;
}
//if one evening isn't selected, four is. make sure the count does indeed in 4
else if (fourEvenings && checkedBoxCount != 4){
//if it doesnt alert the user and return to the form
alert('You must select four dates');
return false;
}
//else, everything checks out!
else {
return;
}
});
});