[英]Validation of survey input on Mechanical Turk
I am using the Amazon Mechanical Turk template to create a survey (HIT) and would like to have the survey questions required. 我正在使用Amazon Mechanical Turk模板创建调查(HIT),并希望提供所需的调查问题。 I have three groups of radio buttons within the survey template that I would like to have all filled out before the form is submitted.
我希望在提交表单之前填写调查模板中的三组单选按钮。 I need help with the validation syntax.
我需要有关验证语法的帮助。
Here's one group of my radio buttons: 这是我的单选按钮的一组:
<div class="radio"><label><strong><input name="ABCD Test" type="radio" value="1" /></strong>Yes</label></div>
<div class="radio"><label><input name="ABCD Test" type="radio" value="2" />No</label></div>
<div class="radio"><label><input name="ABCD Test" type="radio" value="3" />Not sure</label></div>
I found the code below on stack overflow but I am struggling with the syntax on how to make use of it in regards to my specific radio buttons above. 我在堆栈溢出时找到了下面的代码,但是在上面的特定单选按钮方面,我在语法上苦苦挣扎。 Can someone please help with the syntax to
有人可以帮忙语法吗
<script type='text/javascript'>
window.onload = function() {document.getElementById('submitButton').setAttribute('onclick', 'return validateForm()'); }
function validateForm() {
if (validate)
return true;
else
return false;
}
</script>
Please add jQuery and run, should work 请添加jQuery并运行,应该可以运行
//javascript //included jQuery function validateForm() { var vali = $('.radio').find(':checked').length>0; if (vali) return true; else return false; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="" onsubmit="return validateForm();" method="GET"> <div class="radio"><label><strong><input name="ABCD Test" type="radio" value="1" /></strong>Yes</label></div> <div class="radio"><label><input name="ABCD Test" type="radio" value="2" />No</label></div> <div class="radio"><label><input name="ABCD Test" type="radio" value="3" />Not sure</label></div> <input id=submitButton type=submit value="Submit"/> </form>
This should do what you want: 这应该做您想要的:
<script>
function validateRadioButtons()
{
var radios = document.getElementsByName('ABCD Test')
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
alert(radios[i].value);
return true;
}
}
alert("You must check at least one of the radio buttons before submitting.");
return false;
}
</script>
<div class="radio"><label><strong><input name="ABCD Test" type="radio" value="1" /></strong>Yes</label></div>
<div class="radio"><label><input name="ABCD Test" type="radio" value="2" />No</label></div>
<div class="radio"><label><input name="ABCD Test" type="radio" value="3" />Not sure</label></div>
<input type="submit" value="Submit" onClick="validateRadioButtons();" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.