473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

For Loop not working??

Can anyone tell me why this For loop isn't working (see below)
The error message is says:

Error: 'document.emailForm.FNAME_CHILD' is null or not an object

Thanks in advance,
Alan R

// Loop to check if first name field is populated - send info to
childnamecheck function
for(i = 1; i < 6; i++)
{
if (document.emailForm.FNAME_CHILD[i].value !='')
{
childnamecheck(i)
}
}
if (Ok == false)
{
missinginfo += "\n - There is information missing from your Child
details ";
}

Sep 16 '05 #1
8 1679
ASM
er*******@yahoo.co.uk wrote:
Can anyone tell me why this For loop isn't working (see below)
The error message is says:

Error: 'document.emailForm.FNAME_CHILD' is null or not an object

Thanks in advance,
Alan R

// Loop to check if first name field is populated - send info to
childnamecheck function
for(i = 1; i < 6; i++)
you have only 6 elements in your form 'emailForm' ?
'emailForm' is it the *name* of your form ?

each element in this form has same name 'FNAME_CHILD' ?
{
if (document.emailForm.FNAME_CHILD[i].value !='')
{
childnamecheck(i)
}
}
if (Ok == false)
{
missinginfo += "\n - There is information missing from your Child
details ";
}

--
Stephane Moriaux et son [moins] vieux Mac
Sep 16 '05 #2
Lee
er*******@yahoo.co.uk said:

Can anyone tell me why this For loop isn't working (see below)
The error message is says:

Error: 'document.emailForm.FNAME_CHILD' is null or not an object

Thanks in advance,
Alan R

// Loop to check if first name field is populated - send info to
childnamecheck function
for(i = 1; i < 6; i++)
{
if (document.emailForm.FNAME_CHILD[i].value !='')


You haven't given us enough information to do anything but guess.
How are we supposed to know if FNAME_CHILD is correct or not?
It does seem odd that your loop begins with 1. Arrays in Javascript
begin with element zero.

Sep 16 '05 #3
Hi,
Thanks for advice. Here is the code below. It relates to 5 'objects'
in the form, i.e .child's detials:

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

// Check drop down menu - age field and return message
function age(childid)
{
if (childid.selectedIndex >= 13)
alert('Note- Applications for children over 16 years by 30th September
cannot be processed until the child has returned to school after the
summer holidays. Please complete and submit a separate form for these
children.');
}

//Check top half of form submission for missing fields
function checkFields()
{
missinginfo = "";
if (document.emailForm.TITLE.value == "--") {
missinginfo += "\n - Title";
}
if (document.emailForm.FNAME.value == "") {
missinginfo += "\n - First Name";
}
if (document.emailForm.LNAME.value == "") {
missinginfo += "\n - Surname";
}
if (document.emailForm.ADDRESS.value == "") {
missinginfo += "\n - Address";
}
if (document.emailForm.POSTCODE.value == "") {
missinginfo += "\n - Postcode";
}
if (document.emailForm.NI_NUMBER.value == "") {
missinginfo += "\n - National Insurance Number";
}
if((document.emailForm.IS_JSA.value == "NO") &&
(document.emailForm.HOUSING_CT.value == "NO"))
{
missinginfo += "\n - You have not selected any benefits";
}
if (document.emailForm.DEC_YES.value != "Yes") {
missinginfo += "\n - You have not agreed to the declaration";
}
// Loop to check if first name field is populated - send info to
childnamecheck function
//for(i = 1; i < 6; i++)
//{
//if (document.emailForm.FNAME_CHILD[i].value !='')
// {
// childnamecheck(i)
// }
//}
//if (Ok == false)
// {
// missinginfo += "\n - There is information missing from your
Child details ";
// }

var Ok = new Boolean;
Ok = true;

for(i = 1; i < 6; i++) {
if (!/\S/.test (document.emailForm['FNAME_CHILD' +i].value))
childnamecheck(i)
}
if (!Ok) missinginfo += '\n - There is information missing from your
Child details ';
// final output message
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}


// Function to check the rest of the fields
function childnamecheck(num)
{
if(document.emailForm['FNAME_CHILD' +num].value =='')
{
Ok = false;
}
if(document.emailForm['LNAME_CHILD' +num].value =='')
{
Ok = false;
}
if(document.emailForm['DAY_CHILD' +num].value =='--')
{
Ok = false;
}
if(document.emailForm['MONTH_CHILD' +num].value =='---')
{
Ok = false;
}
if(document.emailForm['YEAR_CHILD' +num].value =='----')
{
Ok = false;
}
if(document.emailForm['AGE_CHILD' +num].value =='--')
{
Ok = false;
}
if(document.emailForm['SEX_CHILD' +num].value =='-')
{
Ok = false;
}
if(document.emailForm['SCHOOL_CHILD' +num].value =='select:')
{
Ok = false;
}
}

</SCRIPT>

Sep 16 '05 #4
// Loop to check if first name field is populated - send info to
childnamecheck function
//for(i = 1; i < 6; i++)


should be

for(i = 0; i < 5; i++)
Sep 16 '05 #5
shoot, I changed that - doesn't have any effect. It runs now, but just
comes out that everything is true, even when there are errors!

Sep 16 '05 #6
Lee
er*******@yahoo.co.uk said:

Hi,
Thanks for advice. Here is the code below. It relates to 5 'objects'
in the form, i.e .child's detials:


What I meant was that without seeing the HTML that defines the
fields that you're accessing, we can only guess why you're
having trouble accessing them.

Try creating an example by trimming your actual page down to the
smallest subset that demonstrates the problem. Often you will
spot the problem yourself in the process. If not, post the example
and we should have all the information we need to find the problem.

Sep 16 '05 #7
Lee
er*******@yahoo.co.uk said:

shoot, I changed that - doesn't have any effect. It runs now, but just
comes out that everything is true, even when there are errors!


You've declared your variable "Ok" to be local to function checkFields(),
but seem to try to set its value in function childnamecheck()

Also note that the lines:

var Ok = new Boolean;
Ok = true;

- Create a local variable named Ok.
- Creates a new Boolean object and assigns it to Ok
- Then destroys that object, replacing it with a primitive boolean
value of true.

I would replace them with:

var Ok = true;

and then have childnamecheck() return true or false, rather than
assign a value to Ok, and call it as:

Ok &= childnamecheck(i);

The &= operator assigns to Ok the logical AND of the returned
value with the current value of Ok, so that Ok doesn't simply
reflect whether or not the last value checked is valid.

Sep 16 '05 #8
Thanks a lot, that got it working. Your a star!
Ta again.

Cheers,
Alan R

Sep 16 '05 #9

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

Similar topics

4
by: Ken Fine | last post by:
I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop, and it ain't working -- I'm getting a syntax error....
8
by: Drew | last post by:
I am building an application for keeping track of user permissions here at work. I have built the interfaces, and am now working on the processing page for inserting to the database. I am having...
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
5
by: L. Oborne | last post by:
I have this code working fine in Classic ASP but I get compile errors when I try to run it as ASP.NET. Do While NOT RS.EOF If ... Then... Else... End If RS.MoveNext Loop
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: mrjoka | last post by:
hi experts, i'm developing a page in ASP but i'm doing also some javascript insode the page. i'm creating a frame and i want to loop this frame with a duplicateloop function so the form will be...
2
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with...
6
by: uche | last post by:
This function that I have implemented gives me an infinite loop. I am trying to produce a hexdum program, however, this function is not functioning correctly.....Please help. void...
4
by: joaotsetsemoita | last post by:
hello everyone. Im trying to time out a loot after a certain time. Probably 5 to 10 minutes. I have the following function Private Sub processFileCreation(ByVal source As Object, ByVal e As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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,...

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.