无线电输入的验证返回一个错误 [英] Validation of radio inputs returns a error

查看:84
本文介绍了无线电输入的验证返回一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经坚持了一段时间,现在无法弄清楚为什么无线电验证不适用于我当前的项目,但如果窗体除了单选按钮本身没有其他功能,那么它将起作用。我知道这与Error.txt有关。



欢迎任何想法:)

解决这个问题是你的 validateForm(form)函数期望表单作为参数,但是在你的 onsubmit code>处理程序,您不会传递表单。



更改onsubmit,以便您传递 this 到函数:

pre $ < form name =contactformaction =#onsubmit =return validateForm(this) ; method =postenctype =multipart / form-data>

另外,从您的提交中删除 onclick 按钮,否则验证将激发两次。



最后,不是您的主要问题,而是您引用 x.length 这是没有声明。






注意:您不需要 form.submit ),因为如果任何验证错误发生,您返回 false ,因此如果所有验证都正常,表单将继续提交。

Ive been stuck on this for some time now and cant figure out why the radio validation will not work on my current project, but if the form has no other functions other than the radio buttons itself then it will work. I know it has something to do with the Error.txt

any ideas are welcome :)

解决方案

This issue is your validateForm(form) function is expecting the form as an argument, but in your onsubmit handler, you don't pass the form.

Change the onsubmit so that you pass this to the function:

<form name="contactform" action="#" onsubmit="return validateForm(this);" method="post" enctype="multipart/form-data">

Also, remove the onclick from your submit button, otherwise the validation will fire twice.

Finally, not your main issue but you refer to x.length which is not declared.


Side note: you don't need the form.submit() at the end of the function because you return false if any validation error ocurrs, therefore the form will continue to submit if all validation is OK.

这篇关于无线电输入的验证返回一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆