Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit validation

Status
Not open for further replies.

anveshan

Programmer
Dec 20, 2005
15
US
i have got some text boxes and select boxes at the top arranged individually and then a table with about ten columns and 4 rows with provision to add more. a validation is required on submit form that if the first or any of the required field in any row is populated then other required fields must have some value:

for that for that the code is in this way. -1 is the value of sform:elect box when no selection is made just 'Select One'
function onValidation()
if (form.textfield1.value=="-1")
{ alert ("Please give value);
form.textfield1.focus();
return false; //like this for all non tabular field
}
if (form.tablefield1[0].value=="-1")
{ alert ("Please give value);
form.textfield1[0].focus();
return false;
} //like this for the [0] value for all required fields
for (i = 1; i < frm.tablefield1.length; i++)
{
if (form.tablefield1.value != "-1") || (form.tablefield2.value != "")
{
if (form.tablefield1.value=="-1")
{ alert ("Please give value);
form.tablefield1[1].focus();
return false;// like this for all the required fields
}

return true
}
But it does not allow me to submit till i have filled in all the required field in all the visible line though i may not select any column in the 2, 3 0r 4th rows. where is the problem.

also in one of the tabular fields i want a text field be visible if 'any else' is selected in the selection box.
However. i tried with a function 'GeElementByid for the optional block with style display but some how it fails to response. my tabular fieds run run as for num= 1 to rowCnt
and input values are like 'request("tablefield1")(num)'.
Any suggestions
 
Did you copy and paste your code in here, or type it in fresh? If you copied and pasted, you're missing an opening curly brace right after the function name.

Don't type the code in, always copy and paste so we get the exact code you're working with, and aren't wasting time chasing a problem in the typed code that isn't in the original.

Lee
 
I am sorry but I copy pasted most of the code accept for the start of function.
The starting curly bracket is there in the original code. It somehow is not acceping the -1 value after the (i) and forcing to complete all the lines. I have to work it out fast.
 
This is the part of copy pasted code: it forces to go to complete all the lines of the code. Is there a logic problem?

function onValidation()
{

if (reqfrm.txtfield1.value == "")
{
alert("Please provide value");
form.txtfield1.focus();
return false;
}
//like this for all non tabular field
if (form.tblfield1[0].value == "-1")
{
alert("Please provide value ");
form.tblfield1[0].focus();
return false;
}

//like this for all tabular field
//-1 is the selection valie for not selecting 'Select One')
for (var i = 1; i < form.tblfield1.length; i++)
{
if ((form.tblfield1.value != "-1") || (form.tblfield2.value != ""))

{

if (form.tblfield1.value == -1)
{
alert("Please provide value");
form.tblfield1.focus();
return false;
}
//Like this for all tabular fields
}
}

return true;
}
 
the above file is part of an asp file. where num= 1 to rowNum
is applies to all the tblfield columns.
Any other suggestion how can I submit the form by completing only the required lines and not all the lines in the table will
be highly appreciated.
 
Here you call your form one thing:
Code:
if (reqfrm.txtfield1.value == "")
and here you call it something else:
Code:
form.txtfield1.focus();
.....
if (form.tblfield1[0].value == "-1")
I recommend you using the format document.forms['reqfrm'].elements['elementnamehere'], if that's what your form name is.

As well, for dropdown lists, you need to use something like

document.forms['reqfrm'].elements['selectnamehere'][selectedIndex].value

rather than what you have now.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top