问题
I have a mturk survey and would like to validate the results when clicking the submit button. I found out there is one way discussed here. However, that does not seem to work. Does anyone have any idea?
My code (JS part):
<script type="text/javascript">
window.onload = function() {document.getElementById('submitButton').setAttribute('onclick', 'return validateForm()'); }
function validateForm() {
alert("test");
return false;
}
There is no alert and the submission succeeded.
回答1:
With the new Crowd HTML Elements, you can hook into the submit event and do your pre-validation like this:
document.querySelector('crowd-form').onsubmit = function(e ) {
if (!validateForm()) {
e.preventDefault();
}
}
Thank you,
Amazon Mechanical Turk
来源:https://stackoverflow.com/questions/54266891/submission-validation-with-the-crowd-template-on-mturk