javascript validation/prevent submit form amazon mechanical turk

余生颓废 提交于 2019-12-04 23:10:50

I found a way to do it:

I added a function to the submit button:

<script type='text/javascript'>
window.onload = function() {document.getElementById('submitButton').setAttribute('onclick', 'return validateForm()'); }



function validateForm() {
if (validate)
return true;
else
return false;
}
</script>

Here's an example of doing the validation with jQuery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
  $('#submitButton').click(function() {
    if ($('input[name=myField]').val() == '') {
      alert('myField is required.');
      return false;
    }
    return true;
  });
});
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!