回答編集履歴

1

追記

2016/12/13 07:53

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -49,3 +49,93 @@
49
49
 
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ # 追記
56
+
57
+ ご提示のソースだとidがユニークでないので問題です。
58
+
59
+ また、必須項目の情報をタグに持たせるかどうかは微妙ですね。
60
+
61
+ プログラム側で判断するなら、こんな感じです
62
+
63
+ ```HTML
64
+
65
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
66
+
67
+ <script>
68
+
69
+ $(function(){
70
+
71
+ $("#form").on('submit',function(e){
72
+
73
+ var flg=$(this).find('input[name="question1[]"]:checked').length==0;
74
+
75
+ if(flg){
76
+
77
+ e.preventDefault();
78
+
79
+ alert("1つ以上選択してください");
80
+
81
+ }
82
+
83
+ });
84
+
85
+ });
86
+
87
+ </script>
88
+
89
+
90
+
91
+ </head>
92
+
93
+ <body>
94
+
95
+
96
+
97
+ <form action ="send.php" method="post" id="form">
98
+
99
+ <h1 align="center">あんけえと</h1>
100
+
101
+ <hr>
102
+
103
+ <div class="question" align="center">
104
+
105
+ <p>Q1.くえすちょん</p>
106
+
107
+ <p align="left" style="display:inline-block;">
108
+
109
+ <input type='checkbox' name='question1[]' value='いち'>いち<br>
110
+
111
+ <input type='checkbox' name='question1[]' value='に'>に<br>
112
+
113
+ <input type='checkbox' name='question1[]' value='さん'>さん<br>
114
+
115
+ <input type='checkbox' name='question1[]' value='よん'>よん<br>
116
+
117
+ <input type='checkbox' name='question1[]' value='ご'>ご<br>
118
+
119
+ <input type='hidden' name='question_id' value='1'>
120
+
121
+ </p>
122
+
123
+ </div>
124
+
125
+ <div align="right">
126
+
127
+ <input type="submit" value="送信する" id="send" name="send" style="width:100px; height:30px;">
128
+
129
+ </div>
130
+
131
+ </form>
132
+
133
+ <div id="error">
134
+
135
+ </div>
136
+
137
+ </body>
138
+
139
+ </html>
140
+
141
+ ```