General discussion

Locked

validation check of table in asp

By Arati ·
Hello programers!

I have created table in asp by using loop it working nicely.

but while doing validation,
1. the loop created in javascript for validation is checking the first row of table & then it comes out from the loop

2. the loop is checking the textbox and gives the message also but does not focus that text box it goes to the other textbox of the row.

email me for table code if required.(due to limit of max.len

<script>
function isempty(t)
{
if(t.value == "")
return true;
else
return false;
}
function checkIschar(z)
{
if (isNaN(z.value)== true)
return 'y';
else
return 'n';
}
function checkfields(f,b)
var ff,element1,element2,element3,element4,element5,element6;
for(ff = 1;ff >= f ; ff++);
{
element1 = eval('document.f1.name'+ ff);
element2 = eval('document.f1.age' + ff);
element3 = eval('document.f1.cmb' + ff);
element4 = eval('document.f1.workingfield' + ff);

if (isempty(element1)==true)
{
element1.focus()
}
else if(checkIschar(element1) == 'n')
{
element1.focus()}
else if (isempty(element2)==true)
{
element2.focus()
}
else if(checkIschar(element2) == 'y')
{
element2.focus()
}

else if (element3.selectedIndex==0)
{
element3.focus();
}
else if (element3.selectedIndex==2)
{
if (isempty(element4)==true)
element4.focus()
if(checkIschar(element4) == 'n')
{
element4.focus()
}
}
else if (ff ==> f)
document.f1.submit();
}
}
</script>
Thanks

This conversation is currently closed to new comments.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

validation check of table in asp

by Jay Eckles In reply to validation check of table ...

Have you tried removing the semicolon after the for loop?
for(ff = 1;ff >= f ; ff++);

My interpretation is that the semicolon will make the for loop a stand-alone line: ff count from 1 to f, then the execution moves on to the next code block, contained in braces that you think are attached to the for loop; really they just identify a code block. The code is executed linearly, and when it gets to the bottom, it's done, which is why the code only goes through once.

Collapse -

validation check of table in asp

by Jay Eckles In reply to validation check of table ...

After looking at the code a little longer, it turns out that the problem is both the semicolon that I mentioned above AND the face that the wrong comparison operator is used in the for loop - it should be
for(ff = 1;ff <= f ; ff++) //correct
not
for(ff = 1;ff >= f ; ff++); //incorrect

Collapse -

validation check of table in asp

by Arati In reply to validation check of table ...

Poster rated this answer

Collapse -

validation check of table in asp

by Shanghai Sam In reply to validation check of table ...

Have you tried removing the semicolon after the for loop?
for(ff = 1;ff >= f ; ff++);

My interpretation is that the semicolon will make the for loop a stand-alone line: ff count from 1 to f, then the execution moves on to the next code block, contained in braces that you think are attached to the for loop; really they just identify a code block. The code is executed linearly, and when it gets to the bottom, it's done, which is why the code only goes through once.

Collapse -

validation check of table in asp

by Arati In reply to validation check of table ...

Poster rated this answer

Collapse -

validation check of table in asp

Hello guardian,
In the script after focusing to the form element
follow any one the methods.
1) Give a "return true;" statement to exit from the function.
2) Give a "break;" statement to exit from the for loop.

Since after validating the form fields, the execution of the loop continues, so the focus is at the last loop's form elements.

If u use return or break, the execution of loop will be terminated immediately after focussing to the form field.

Collapse -

validation check of table in asp

by Arati In reply to validation check of table ...

Poster rated this answer

Collapse -

validation check of table in asp

for(ff = 1;ff >= f ; ff++);

In the for Loop,
1) Remove the semi-colon at the end;
2) Change the ">=" symbol to "<=".

Collapse -

validation check of table in asp

by Arati In reply to validation check of table ...

Poster rated this answer

Collapse -

validation check of table in asp

by Arati In reply to validation check of table ...

Thanks jay & Kannan
it Works nicely
i have to ask one thing as i send my code earlier if i want to focus on element during loop
i have to write like this (see it is right in all aspect while my site is start)
code :
if (isempty(element1)==true)
{
alert("Please enter field name");
element1.focus()
break
}
Thanks
arti

Back to Web Development Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums