回答編集履歴
1
追記
answer
CHANGED
@@ -23,4 +23,49 @@
|
|
23
23
|
<input type="button" value="check">
|
24
24
|
</form>
|
25
25
|
|
26
|
+
```
|
27
|
+
|
28
|
+
# 追記
|
29
|
+
ご提示のソースだとidがユニークでないので問題です。
|
30
|
+
また、必須項目の情報をタグに持たせるかどうかは微妙ですね。
|
31
|
+
プログラム側で判断するなら、こんな感じです
|
32
|
+
```HTML
|
33
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
34
|
+
<script>
|
35
|
+
$(function(){
|
36
|
+
$("#form").on('submit',function(e){
|
37
|
+
var flg=$(this).find('input[name="question1[]"]:checked').length==0;
|
38
|
+
if(flg){
|
39
|
+
e.preventDefault();
|
40
|
+
alert("1つ以上選択してください");
|
41
|
+
}
|
42
|
+
});
|
43
|
+
});
|
44
|
+
</script>
|
45
|
+
|
46
|
+
</head>
|
47
|
+
<body>
|
48
|
+
|
49
|
+
<form action ="send.php" method="post" id="form">
|
50
|
+
<h1 align="center">あんけえと</h1>
|
51
|
+
<hr>
|
52
|
+
<div class="question" align="center">
|
53
|
+
<p>Q1.くえすちょん</p>
|
54
|
+
<p align="left" style="display:inline-block;">
|
55
|
+
<input type='checkbox' name='question1[]' value='いち'>いち<br>
|
56
|
+
<input type='checkbox' name='question1[]' value='に'>に<br>
|
57
|
+
<input type='checkbox' name='question1[]' value='さん'>さん<br>
|
58
|
+
<input type='checkbox' name='question1[]' value='よん'>よん<br>
|
59
|
+
<input type='checkbox' name='question1[]' value='ご'>ご<br>
|
60
|
+
<input type='hidden' name='question_id' value='1'>
|
61
|
+
</p>
|
62
|
+
</div>
|
63
|
+
<div align="right">
|
64
|
+
<input type="submit" value="送信する" id="send" name="send" style="width:100px; height:30px;">
|
65
|
+
</div>
|
66
|
+
</form>
|
67
|
+
<div id="error">
|
68
|
+
</div>
|
69
|
+
</body>
|
70
|
+
</html>
|
26
71
|
```
|