我有一个form
确实提交了8个radio
按钮中的1个到php
$_POST
超全局数组。因此,我需要一些验证。我是好心通过提供这个代码的伟大工程帮助:JQuery验证与多组单选按钮
$("#form").submit(function (event) {
if(!$(":radio:checked").length) {
alert("You must select at least one emotional state!");
event.preventDefault();
}
});
不过,我现在已经被要求有2套,其中用户选择2分的答案,而不是最初的1个回答8个radio
按钮。我需要代码才能确定在提交表单之前,已从每组8个按钮中选择了至少一个radio
按钮。代码检查是否有radio
按钮被选中,然后只要选择了1个按钮,该功能即被满足并转换到下一页,这不是我想要的。
编辑
按钮代码:
<p><input type="radio" value="happy" name="perceived_emotion">Happy
<input type="radio" value="excited" name="perceived_emotion">Excited
<input type="radio" value="angry" name="perceived_emotion">Angry
<input type="radio" value="frustrated" name="perceived_emotion">Frustrated
<input type="radio" value="miserable" name="perceived_emotion">Miserable
<input type="radio" value="sad" name="perceived_emotion">Sad
<input type="radio" value="tired" name="perceived_emotion">Tired
<input type="radio" value="relaxed" name="perceived_emotion">Relaxed</p>
<p><input type="radio" value="happy" name="induced_emotion">Happy
<input type="radio" value="excited" name="induced_emotion">Excited
<input type="radio" value="angry" name="induced_emotion">Angry
<input type="radio" value="frustrated" name="induced_emotion">Frustrated
<input type="radio" value="miserable" name="induced_emotion">Miserable
<input type="radio" value="sad" name="induced_emotion">Sad
<input type="radio" value="tired" name="induced_emotion">Tired
<input type="radio" value="relaxed" name="induced_emotion">Relaxed</p>
这里是form
代码:
<form id="form" action="audio_handler.php?id=1" method="POST">
<div id="perceived_emotions">
<?php include("includes/induced_emotion_buttons.php"); ?>
</div>
<br />
<div id="induced_emotions">
<?php include("includes/perceived_emotion_buttons.php"); ?>
</div>
<p class="right"><input type="submit" name="submit" value="Submit"></p>
</form>
我们需要更多的代码,例如:radio:checked来自哪里? 请在页面上显示HTML和任何其他javascript/jquery:D – 2014-11-24 21:54:55
现在就编辑我的帖子。 – user1574598 2014-11-24 21:59:37
首先,您需要将单选按钮转换为复选框。 – 2014-11-24 22:13:55