检查和验证脚本 [英] checking and validating script

查看:54
本文介绍了检查和验证脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有4个表单,所有四个表单都有不同数量的文本框。有没有

a脚本我可以用来检查以确保表格上的所有内容都不是

空白?

Say I have 4 forms, all four have different numbers of text boxes. is there
a script that I can use to check to make sure everything on the form is not
blank?

推荐答案

Samir写道:
Samir wrote:
说我有4个表单,所有四个表单都有不同数量的文本框。是否有一个脚本,我可以用它来检查以确保表格上的所有内容都不是空白的?
Say I have 4 forms, all four have different numbers of text boxes. is there
a script that I can use to check to make sure everything on the form is not
blank?




功能verifyNoBlankEntries(){


//循环表单:

var f = document.forms.length;

while(f - )$

//遍历每个表单控件:

fc = document.forms [f] .length;

for(k = 0; k

//寻找空文本框

if(document.forms [f] [ k] .type ==" text"&& document.forms [f] [k] .value ==""){

alert(" empty field"); document.forms [f] [k] .focus();返回false;

}

}

}

返回true;

}


Mick



function verifyNoBlankEntries(){

//Loop through forms:
var f= document.forms.length;
while(f--){

// loop through each form control:
fc=document.forms[f].length;
for(k=0;k<fc;k++){

// look for empty text boxes
if(document.forms[f][k].type=="text" && document.forms[f][k].value==""){
alert("empty field");document.forms[f][k].focus();return false;
}
}
}
return true;
}

Mick


谢谢,它有效完美。


还有一件事,是否可以在文本框中添加描述,以便

警告可以告诉他们它是什么字段?这也适用于下降

起来还不错?


我知道我很挑剔。

Mick White ; < MW ****** @ BOGUSrochester.rr.com>在消息中写道

新闻:Xi ****************** @ twister.nyroc.rr.com ...
Thanks, it works perfect.

One more thing, is it possible to add a description to a textbox so that
the warning can tell them what field it is?? does this also work for drop
downs as well right?

I know I am being picky.
"Mick White" <mw******@BOGUSrochester.rr.com> wrote in message
news:Xi******************@twister.nyroc.rr.com...
Samir写道:
Samir wrote:
说我有4个表单,所有四个表单都有不同数量的文本框。是
有一个脚本,我可以用来检查以确保表格上的所有内容都是
不是空白的?
Say I have 4 forms, all four have different numbers of text boxes. is there a script that I can use to check to make sure everything on the form is not blank?



函数verifyNoBlankEntries(){

//循环表格:
var f = document.forms.length;
while(f - ){

//循环每个表单控件:
fc = document.forms [f] .length;
for(k = 0; k
//查找空文本方框
if(document.forms [f] [k] .type ==" text"&& document.forms [f] [k] .value ==""){
alert(" empty field"); document.forms [f] [k] .focus(); return false;
}
}
}
返回true;
}

Mick



function verifyNoBlankEntries(){

//Loop through forms:
var f= document.forms.length;
while(f--){

// loop through each form control:
fc=document.forms[f].length;
for(k=0;k<fc;k++){

// look for empty text boxes
if(document.forms[f][k].type=="text" && document.forms[f][k].value==""){
alert("empty field");document.forms[f][k].focus();return false;
}
}
}
return true;
}

Mick



Samir写道:
Samir wrote:
谢谢,它工作完美。

还有一件事,是否可以在文本框中添加描述,以便警告可以告诉他们哪个字段是什么?


是的(例如,在大多数浏览器中),您可以将

空白字段的背景更改为令人震惊的粉红色你喜欢。你会在哪里看b / b
出现的描述/警告?

这对下拉也有效吗?
Thanks, it works perfect.

One more thing, is it possible to add a description to a textbox so that
the warning can tell them what field it is??
Yes it''s possible (in most browsers), you could,for example, change the
empty field''s background to shocking pink if you like. Where would you
like the description/warning to appear?
does this also work for drop downs as well right?



不,但你可以确保选择某些东西,或者更确切地说,如果选择有值,则确定



if(document.forms [f ] [k] .type ==" select-one"&&!document.forms [f] [k] .value){

alert(" select from the + document.forms [f] [k] .name +" menu");

返回false;

}


如果您使用所有菜单中的第一个插槽,例如

" Select a ...",则可以重写前面的代码:


if(document.forms [f] [k] .type ==" select-one"&&

!document.forms [f] [k] .selectedIndex){提醒(...}

看看你是否可以将上面的代码合并到你的页面中,如果你被卡住了,请告诉我。


这些表单中的所有4个都是以某种方式提交的T'我很好奇。


Mick


以下原始功能。


function verifyNoBlankEntries( ){$ / $

//循环表格:

var f = document.forms.length;

while(f-- )$

//遍历每个表单控件:

fc = document.forms [f] .length;

for (k = 0; k

//寻找空文本框

if(document.forms [f] [k] .type ==" text"&& document.forms [f] [k] .value ==""){

alert(" empty field"); document。 form [f] [k] .focus(); return false;

}

}

}

返回true;

}


No, but you can make sure that something is selected, or more precisely,
if the selection has a value:

if(document.forms[f][k].type=="select-one" && !document.forms[f][k].value){
alert("Select something from the "+document.forms[f][k].name+" menu");
return false;
}

Ur if you use the first slot in all of the menus for something like
"Select a ... ", you could rewrite the preceding code:

if(document.forms[f][k].type=="select-one" &&
!document.forms[f][k].selectedIndex){alert( ...}
See if you can incorporate the code above into your page, let me know if
you get stuck.

Do all 4 of these forms get submitted at some point? I''m curious.

Mick

Original function below.

function verifyNoBlankEntries(){

//Loop through forms:
var f= document.forms.length;
while(f--){

// loop through each form control:
fc=document.forms[f].length;
for(k=0;k<fc;k++){

// look for empty text boxes
if(document.forms[f][k].type=="text" && document.forms[f][k].value==""){
alert("empty field");document.forms[f][k].focus();return false;
}
}
}
return true;
}


这篇关于检查和验证脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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