PDA

View Full Version : javascript problem


phani
11-29-2002, 10:38 AM
can any one tell what's wrong in the code:

function check()
{
objList=new Array(0);
for(var i=0;i<document.forms[0].elements.length;i++)
{
if(document.forms[0].elements[i].style.display!="none")
objList.push(document.forms[0].elements[i].name);
}
for (i=0;i<objList.length;i++)
{
if (isEmpty(document.forms[0][objList[i][0]].value))
{
alert("Please dont leave this field empty, enter some value");
document.forms[0][objList[i][0]].focus();
return false;
}
}
return true;
}

i have stored the elements which r visible into an array and i need to access the elements(form elements) of the array and their values.

Adam20002
11-29-2002, 12:29 PM
What error messages are ypu recieving ? Do you have a link to this code in operation ?

I noticed that you are storing form element names in an array objList and then accessing them as objList[i][0]. To access an array element you can just use its index, such as objList[i] where i equals 0 will pull the first array element from the array.

phani
11-30-2002, 05:11 AM
i know the how to access the variables stored in a array. but i need to know is how to access those form elements values stored in a array

iam getting the following error:

'document.forms.0[...].value' is null or not an object