我试图阻止提交的表单,如果验证失败,但它目前不工作。 onclick方法用于隐藏输入,但其onsubmit方法失败。有任何想法吗?Javascript/PHP验证
<input type="submit" class="btn ccm-input-submit" id="register" name="register" value="Register" onsubmit="return validation(this)" onclick="copytextbox()"/>
<?php echo $form->hidden('rcID', $rcID); ?>
<script>
function copytextbox()
{
var textToCopy = document.getElementById('school').value;
var whereToCopy = document.getElementById('<?php echo $school ?>');
whereToCopy.value += textToCopy;
}
function validation(f)
{
var schoolText = document.getElementById('school').value;
if (schoolText == '') {
alert('Please Choose a value from the dropdown box.');
return false; // stop submission until textbox is not ''
} else {
f.submit();
return false;
}
}
</script>
此外,即时通讯尝试看看是否值是一个数组中的一员,我尝试使用的indexOf(schoolText)等,但这个也失败了,亲切的问候
用于前walidation使用f] [query.validate](https://github.com/DiegoLopesLima/Validate#readme),为PHP验证使用[尊重/验证](https://github.com/Respect/Validation) – walkingRed 2015-03-13 14:43:59
请记住,黑客可以轻松绕过浏览器内验证。 – hanshenrik 2015-03-13 18:48:04