问题描述
大家好,
我陷入了项目的一部分,即验证.我有一个带有文本框和下拉列表的设备输入字段.我编写了一个javascript,直到在ONE文本框中输入了某些内容后,才禁用提交按钮,但是如果其他字段为空,它只会使按钮保持打开状态.
我想让客户端在所有字段中输入,然后启用提交"按钮.
这是我写的Javascript
Hey guys,
I''m stuck on one part of my project, the validation. I have an Equipment entry field with text boxes and drop down lists. I''ve written a javascript that Disables the submit button until something is entered into ONE textbox, but then it just leaves the button open if the other fields are empty.
I want to have the client enter in all the fields then the submit button become enabled.
Here is the Javascript I have written
function Validate() {
if (document.getElementById("<%=btnSubmit.ClientID%>").disabled == true) {
var serial = document.getElementById("<%=btnSubmit.ClientID%>");
serial.disabled = false;
}
}
我有5个文本框,我想确保在启用提交之前它们都包含文本.
我只有一个盒子有一条生产线,但是我不知道如何为许多盒子做这条生产线?
I''ve 5 text boxes and I want to ensure they all have text in them before the submit becomes enabled.
I have a line for just one box, but I don''t know how to do it for many boxes?
SerialNum.Attributes.Add("OnKeyDown", "Validate()");
有人可以为此提供帮助吗?页面加载中的Switch语句可能吗?如果是的话,我该怎么写才是最令人困惑的地方.如果您什至可以做2个文本框,我自己去做其余的事情.
谢谢你们,我希望这是有道理的,您可以提供帮助.
Would anyone be able to provide help for this? A Switch statement in the page load maybe? and if so HOW do I write it is the most confusing bit. If you could do even 2 text boxes I''d do the rest myself.
Thanks Guys and I hope this made sense and you can help out.
推荐答案
function Validate()
{
var inputField1 = document.getElementById("<%=inputField1.ClientID%>");
var inputField2 = document.getElementById("<%=inputField2.ClientID%>");
if(inputField1.value.length > 0 && inputField2.value.length > 0)
document.getElementById("<%=btnSubmit.ClientID%>").disabled = false;
else
document.getElementById("<%=btnSubmit.ClientID%>").disabled = true;
}
CodeBehind文件:
CodeBehind file:
inputField1.Attributes.Add("onblur", "Validate()");
inputField2.Attributes.Add("onblur", "Validate()");
这应该做.
P.S .:有一种方法可以使使用jQuery变得容易,但这需要一些知识.
PS2:也有验证程序控件,但是当前解决方案基于要求.
This should do.
P.S.: There is way to make it easy using jQuery but that would need a little knowledge about it.
P.S.2: There are validator controls too that does it but current solution is based on as asked.
function validation()
{
if(
这篇关于使用Javascript进行C#文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!