 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 19th, 2006, 09:23 AM
|
|
Authorized User
|
|
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Form Validation
Hi,
I'm trying to validate a form using JavaScript and I'm having a hard time to grasp the language I cannot get it to pass the second IF statement, unless everything is filled. But if I return true
then it ignores the other fields.
Here is the script:
function ValidateFormEdit(frmEdit)
{
if (""==document.forms.frmEdit.lpartno.value)
{alert("PART NUMBER is a required field.");
document.forms.frmEdit.lpartno.focus();
return false;}
if (""==document.forms.frmEdit.lrefpartno.value)
{var answer = confirm("Leaving REFERENCE PART blank will disable the SKU");
if (answer==true)
{document.forms.frmEdit.lrefpartdesc.value="";
document.forms.frmEdit.lstatus.value="REMOVE";
document.forms.frmEdit.ldisabled.value=0;
return false;
}
else
{document.forms.frmEdit.lrefpartno.focus();
return false;}
}
if (""==document.forms.frmEdit.lrefqty.value)
{ alert("QTY is required");
document.forms.frmEdit.lrefqty.focus();
return false;}
if (""==document.forms.frmEdit.lfactoryid.value)
{ alert("Please select a BU.");
document.forms.frmEdit.lfactoryid.focus();
return false;}
if (""==document.forms.frmEdit.lskuno.value)
{var skuanswer=confirm("Leaving SKU blank will map this to the whole BU.");
if (skuanswer==true)
{document.forms.frmEdit.lskuno.value="#ALL#";
return false;}
else
{document.forms.frmEdit.lskuno.focus();
return false;}
}
if (""==document.forms.frmEdit.lfromdate.value)
{ alert("FROM DATE is required.");
document.forms.frmEdit.lfromdate.focus();
return false;}
if (""==document.forms.frmEdit.ltodate.value)
{ alert("TO DATE is required.");
document.forms.frmEdit.ltodate.focus();
return false;}
}
Strange and crazy, but everything is possible
__________________
=======================
Strange and crazy, but everything is possible
|
|

October 19th, 2006, 09:31 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Ok since I dont know your business rules I can't break down the code, but you can so here is the 35,000 foot view. When you use return in a function, it stops the process false means the function failed, true means it passed.
What you should do, is right before the closing brace of your function add a return true; What this will do is, if all the if's are skipped over, the function returns true and the form submits else the javascript will return false and the form wont submit.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|

October 19th, 2006, 11:33 AM
|
|
Authorized User
|
|
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
:D
Thanks Man!
That worked like a charm.. I can't belive it was just that...
Quote:
quote:Originally posted by dparsons
Ok since I dont know your business rules I can't break down the code, but you can so here is the 35,000 foot view. When you use return in a function, it stops the process false means the function failed, true means it passed.
What you should do, is right before the closing brace of your function add a return true; What this will do is, if all the if's are skipped over, the function returns true and the form submits else the javascript will return false and the form wont submit.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
Strange and crazy, but everything is possible
|
|

October 19th, 2006, 11:38 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
No worries glad it worked for you.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|
 |