Mozilla/Netscape - don't understand error

N

Neil

Hi,

I'm getting the fololowing error in Mozilla and Netscape, which does not
occur in IE.

'form1 is not defined' at line 195

line 195 is the third line below:

function UpdateTagValues()
{
for (iIndex=0; iIndex<=form1.cboValue.length+1; iIndex++)
{
form1.cboValue.options[0] = null;
}
for (iIndex=0; iIndex<=iTagID.length; iIndex++)
{
if (iTagTypeID[iIndex] == form1.cboType.value)
{
var option = new Option(sTagValue[iIndex], iTagID[iIndex]);
form1.cboValue.options[form1.cboValue.length] = option;
}
}
}and the data refered to is (part):var iTagID = new Array();
var iTagTypeID = new Array();
var sTagValue = new Array();

iTagID[0] = 7;
iTagTypeID[0] = 3;
sTagValue[0] = 'Christmas Card';
iTagID[1] = 8;
iTagTypeID[1] = 3;
sTagValue[1] = 'Test - can be deleted';
iTagID[2] = 9;
iTagTypeID[2] = 5;
sTagValue[2] = 'Chief Executives/Directors';form1 is defined:<form
name="form1" id="form1" method="post" action="">etc...and finally, the
calling element is:<select name="cboType" id="cboType"
onchange="UpdateTagValues();">etc...Any advice appreciated.regards,NEIL
 
R

RobG

Neil said:
Hi,

I'm getting the fololowing error in Mozilla and Netscape, which does not
occur in IE.

'form1 is not defined' at line 195

line 195 is the third line below:

function UpdateTagValues()
{
for (iIndex=0; iIndex<=form1.cboValue.length+1; iIndex++)

iIndex should be kept local, especially if being used as a counter:

for (var iIndex=0; ... )
{
form1.cboValue.options[0] = null;

Here you appear to be using the name of the form as a global variable.
That is an IE-ism that is not supported by most other browsers, use:

document.form1.cboValue.options[0] = null;

or the more strict:

document.forms['form1'].elements['cboValue'].options[0] = null;

Though if the intention is to remove all the options, then just set the
length of the select to zero (0) with no loop:

document.forms['form1'].elements['cboValue'].length = 0;

}
for (iIndex=0; iIndex<=iTagID.length; iIndex++)
{
if (iTagTypeID[iIndex] == form1.cboType.value)
{
var option = new Option(sTagValue[iIndex], iTagID[iIndex]);
form1.cboValue.options[form1.cboValue.length] = option;
}
}
}and the data refered to is (part):var iTagID = new Array();
var iTagTypeID = new Array();
var sTagValue = new Array();

iTagID[0] = 7;

The intention here appears to be to set the ID value as '7'. For valid
HTML, the ID attribute value can't start with a digit, though it can
contain digits elsewhere.

iTagTypeID[0] = 3;
sTagValue[0] = 'Christmas Card';
iTagID[1] = 8;
iTagTypeID[1] = 3;
sTagValue[1] = 'Test - can be deleted';
iTagID[2] = 9;
iTagTypeID[2] = 5;
sTagValue[2] = 'Chief Executives/Directors';

You might find it easier to initialise these arrays (given that the ID
value may need to be modified) using:

iTagID = [7, 8, 9];
sTagValue = ['Christmas Card', 'Test - can be deleted, 'Chief
Executives/Directors'];
iTagTypeID = [3, 3, 5];

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top