473,749 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checking and validating script

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?
Jul 23 '05 #1
10 1383
Samir wrote:
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?


function verifyNoBlankEn tries(){

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

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

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

Mick

Jul 23 '05 #2
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******@BOGUS rochester.rr.co m> wrote in message
news:Xi******** **********@twis ter.nyroc.rr.co m...
Samir wrote:
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?


function verifyNoBlankEn tries(){

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

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

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

Mick

Jul 23 '05 #3
Samir wrote:
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?

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

if(document.for ms[f][k].type=="select-one" && !document.forms[f][k].value){
alert("Select something from the "+document.form s[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.for ms[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 verifyNoBlankEn tries(){

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

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

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

Jul 23 '05 #4
Okay for example you have a textbox
<input type="text" name="T1" size="20">
Say...is there a way to add something like
<input type="text" name="T1" size="20" description="Fi rst Name">
So when they leave it blank, the form validation check would do an alert of
"You have left 'Then right here you would put the description of the
textbox'"
would something like that be possible? Kinda like you did for alert("Select
something from the "+document.form s[f][k].name+" menu");

but is a description or some kind of field that could give a better
description? Same question goes for the drop down as well.

Thanks again!

"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:
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?

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

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

!document.forms[f][k].value){ alert("Select something from the "+document.form s[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.for ms[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 verifyNoBlankEn tries(){

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

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

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

Jul 23 '05 #5
Ohh and I don't really have 4 forms, I was just saying that for an example
so I can use it on any form I have on any page.

Well that's an interesting question, what would I need to do if I had four
forms with different form names that needs checking and needed to be
submitted. I figured it out with one form on a page, the form name is form,
I just put document.form.s ubmit()
"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:
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?

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

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

!document.forms[f][k].value){ alert("Select something from the "+document.form s[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.for ms[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 verifyNoBlankEn tries(){

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

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

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

Jul 23 '05 #6
One more thing

Is it possible to put some kind a flag on a field so that the validation
does not check it(non required field)?

"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:
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?

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

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

!document.forms[f][k].value){ alert("Select something from the "+document.form s[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.for ms[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 verifyNoBlankEn tries(){

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

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

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

Jul 23 '05 #7
Samir wrote:
Okay for example you have a textbox
<input type="text" name="T1" size="20">
Say...is there a way to add something like
<input type="text" name="T1" size="20" description="Fi rst Name">
So when they leave it blank, the form validation check would do an alert of
"You have left 'Then right here you would put the description of the
textbox'"
would something like that be possible?
It would work on some browsers (IE and Safari, to name two), but you
could use the "id" attribute to specify your description.
<input type="text" name="T1" size="20" id="first name">

if(document.for ms[f][k].type=="text" && document.forms[f][k].value==""){
alert("Please enter your
"+document.form s[f][k].id+".");docume nt.forms[f][k].focus();return false;
}
A little kudgy though, better to give your form controls meaningful names.

Kinda like you did for alert("Select something from the "+document.form s[f][k].name+" menu");

but is a description or some kind of field that could give a better
description? Same question goes for the drop down as well.
You could assign your description to the first entry of your menu.

<option value="Your description here"> Please select a colour</option>

alert(document. forms[f][k].options[0].value)

Mick

Thanks again!

"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:

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?

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

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


!document.forms[f][k].value){
alert("Sele ct something from the "+document.form s[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.f orms[f][k].type=="select-one" &&
!document.for ms[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 verifyNoBlankEn tries(){

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

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

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


Jul 23 '05 #8
Samir wrote:
Ohh and I don't really have 4 forms, I was just saying that for an example
so I can use it on any form I have on any page.

Well that's an interesting question, what would I need to do if I had four
forms with different form names that needs checking and needed to be
submitted.
I don't know a foolproof way to do this.
Mick
I figured it out with one form on a page, the form name is form, I just put document.form.s ubmit()
"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:

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?

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

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


!document.forms[f][k].value){
alert("Sele ct something from the "+document.form s[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.f orms[f][k].type=="select-one" &&
!document.for ms[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 verifyNoBlankEn tries(){

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

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

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


Jul 23 '05 #9
Samir wrote:
One more thing

Is it possible to put some kind a flag on a field so that the validation
does not check it(non required field)?
I would add a suffix to the name or the id:

name="zipREQ"

if(document.for ms[f][k].type=="text" && document.forms[f][k].value==""
&& document.forms[f][k].name.indexOf(" REQ") != -1 )

Mick

"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:k9******** ***********@twi ster.nyroc.rr.c om...
Samir wrote:

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?

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

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


!document.forms[f][k].value){
alert("Sele ct something from the "+document.form s[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.f orms[f][k].type=="select-one" &&
!document.for ms[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 verifyNoBlankEn tries(){

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

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

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


Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2641
by: Philip D Heady | last post by:
Hi, I'm validating a simple form for input via post ($PHP_SELF). Near the end I check for username and password. I'm using simple if, elseif, else statements. I require them to enter password twice and check that they match. Problem is script doesn't valide past username input and I dont know why!! If you don't enter a password it doesn't do the validation anymore, it just dies for some reason. I would greatly appreciate anyones help,...
30
3909
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript> everywhere??? i'm writing most of my code by hand, so this is a lot of extra typing or global search and replace later 2. the other problem is with my include files: i usually <script src="foo.js"></script>
6
6328
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
3
654
by: Claire Lescarret | last post by:
Hello, I have devoted my time to write valid html 4.01 strict, and CSS-1 and 2 *but* I also have to use third party's code for webcounter (StatCounter) and Google's SiteSearch, which are preventing my pages from validating. I woudn't like to take away those services, but I also would like to show my valid pages... Any suggestions will be greatly appreciated! Thanks in advance.
2
5106
by: and | last post by:
Hi I have been validating all day most things are cool but I cant get by this problem. One I have listed the script (JAVASCRIPT ) in all the right placesnot a prob but the validator insists on going through t findind < (less than) in the code. why is it going through the script the scripts been tagged correctly? Also in the body where the link to the script is there is a table givng
2
1429
by: Scott Natwick | last post by:
I am having trouble validating that a selection has been made from a RadioButton. I created a script to trigger from a CustomValidator, however, it only works when I run the app locally, from the debugger. Once I upload it to the server and run, the script no longer triggers. Any ideas? Thanks in advance,
2
6594
by: PapaRandy | last post by:
Hello, I am trying to validate the following .py webpage as HTML (through W3C). I put: ----------------------------------------------------------------------------- print "Content-type: text/html; charset=utf-8"
1
1672
mickey0
by: mickey0 | last post by:
hello, validating this file on w3c I have many error: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="java.js"></script>
6
1352
by: phpmagesh | last post by:
Hi I am creating login page with validation. i have index.php page with login box, for validating this login detail i m redirecting to login_validate.php. Login_validate.php file code: <?php
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.