通过单击按钮的简单注册表单进行客户端验证 [英] Client side validation on simple registration form of button click
问题描述
想了解以下网址的工作原理:
www.tradeshows.tradeindia.com/musician-expo2013/register.html
如果任何用户单击提交"按钮时未填写任何信息,则会出现一个javascript弹出窗口,并且必须显示的所有重要字段都被一个一显示.我知道javascript的警报功能,但不知道在其上显示了多个警报消息单个警报,如果单个或多个文本框为空.如何实现此目的?
Would like to know the concept behind the working of the URL below:
www.tradeshows.tradeindia.com/musician-expo2013/register.html
If any user clicks on the submit button without filling any information then a javascript pop up appears and all the important fields that has to displayed is shown one by one, I am aware about alert function of javascript but not aware to shown multiple alert messages on single alert if a single or multiple text box is empty.How to achieve this?
推荐答案
引用 ^ ]
定义一个JavaScript函数进行验证,如下所示:
define a javascript function for validation as below:
function Validate()
{
var flag = true;
var msg = "Following validations failed:";
if(document.getElementByID("txtBox1").value = "")
{
flag = false;
msg += "<br>Enter value for text box 1";
}
if(document.getElementByID("txtBox2").value = "")
{
flag = false;
msg += "<br>Enter value for text box 2";
}
if (flag = false)
{
alert(msg);
return false;
}
else
{
return true;
}
}
将按钮的OnClientClick属性设置为此功能:
set the OnClientClick property of button as this function:
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return Validate();" />
这篇关于通过单击按钮的简单注册表单进行客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!