FayeC
02-14-2008, 03:31 PM
I have a form that needs to be validated and if required fields are empty it should show a warning and focus back on the empty field.
I have that part figured out.
The issue is to add to the code that only after the required fields are filled it should send the page to be printed.
When I add the else statement to window.print() everything fails and the form doesn't even validate anymore. Without the else statment it validades fine.
I have the following:
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(field1,"You need to fill all required fields before this form can be printed.")==false)
{field1.focus();return false;}
if (validate_required(field2,"You need to fill all required fields before this form can be printed.")==false)
{field2.focus();return false;}
if (validate_required(field3,"You need to fill all required fields before this form can be printed.")==false)
{field3.focus();return false;}
else {window.print}
}
}
Any help is appreciated.
FayeC
I have that part figured out.
The issue is to add to the code that only after the required fields are filled it should send the page to be printed.
When I add the else statement to window.print() everything fails and the form doesn't even validate anymore. Without the else statment it validades fine.
I have the following:
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(field1,"You need to fill all required fields before this form can be printed.")==false)
{field1.focus();return false;}
if (validate_required(field2,"You need to fill all required fields before this form can be printed.")==false)
{field2.focus();return false;}
if (validate_required(field3,"You need to fill all required fields before this form can be printed.")==false)
{field3.focus();return false;}
else {window.print}
}
}
Any help is appreciated.
FayeC