02.
<form action=
"checkbox-form.php"
method=
"post"
>
03.
04.
ตัวเลือกที่ 1 <input type=
"checkbox"
id=
"data_item1"
name=
"data_item1"
value=
"1"
class
=
"css_data_item"
/> <br>
05.
ตัวเลือกที่ 1 <input type=
"checkbox"
id=
"data_item2"
name=
"data_item2"
value=
"1"
class
=
"css_data_item"
/><br>
06.
ตัวเลือกที่ 1 <input type=
"checkbox"
id=
"data_item3"
name=
"data_item3"
value=
"1"
class
=
"css_data_item"
/><br>
07.
ตัวเลือกที่ 1 <input type=
"checkbox"
id=
"data_item4"
name=
"data_item4"
value=
"1"
class
=
"css_data_item"
/><br>
08.
<input type=
"submit"
name=
"formSubmit"
value=
"Submit"
/>
09.
</form>
10.
11.
12.
<script type=
"text/javascript"
>
13.
$(
function
(){
14.
15.
$(
".css_data_item"
).click(
function
(){
16.
if
($(this).prop(
"checked"
)==true){
17.
var
indexObj=$(this).index(
".css_data_item"
);
18.
$(
".css_data_item"
).not(
":eq("
+indexObj+
")"
).prop(
"checked"
, false );
19.
}
20.
});
21.
22.
$(
"#form_checkbox1"
).submit(
function
(){
23.
if
($(
".css_data_item:checked"
).length==0){
24.
alert(
"NO"
);
25.
return
false;
26.
}
27.
});
28.
29.
});
30.
</script>