PDA

View Full Version : Simple loop problem


ksridhar69
11-06-2002, 01:32 PM
we have 200 rows. If i enter 2 rows(or more rows) then delete any row focus is going perfectly to 3 rd row. But if i enter 1 row ,then i delete i am getting run time error

if ((trim(document.testform.d[199].value) == ""))
{
var i = 199;
for (i = 199; i < document.testform.d.length; i--)
if (!isBlank(document.testform.d[i].value))
break;
document.testform.d[i+1].focus();
}

krycek
11-06-2002, 02:39 PM
I am not sure what this is in context to. Could you describe a little more about what you are trying to do...? I mean, are these rows in an array, a table, a list of layers... etc.

Your code makes me think it's simply an array issue, but your talk about focus is confusing. Are you simply trying to delete an element from an array?

:confused:

Also, this line appears erroneous:

for (i = 199; i < document.testform.d.length; i--)

you appear to be looping from the last element to the first, in which case it should be:

for (i = 199; i > 0; i--)

or better still:

for (i = document.testform.d.length; i > 0; i--)

however if you are looping from element 199 to the last element, that i-- should surely be an i++?

for (i = 199; i < document.testform.d.length; i++)

If you describe a bit more about what you are doing then I can help :)

::] krycek [::

beetle
11-06-2002, 04:48 PM
It looks like you are trying to loop through a form to check for blank values...instead of a for loop with a fixed limit, why not just loop through the form's elements collection? That's how my validator (http://www.peterbailey.net/fValidate) works.

ksridhar69
11-06-2002, 07:51 PM
it is working

Thanks guys