Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
 
Old October 19th, 2006, 09:23 AM
Authorized User
Points: 245, Level: 4
Points: 245, Level: 4 Points: 245, Level: 4 Points: 245, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: Houston, TX, USA.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default 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
 
Old October 19th, 2006, 09:31 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old October 19th, 2006, 11:33 AM
Authorized User
Points: 245, Level: 4
Points: 245, Level: 4 Points: 245, Level: 4 Points: 245, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: Houston, TX, USA.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default

: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
 
Old October 19th, 2006, 11:38 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Form Validation Stanny Access VBA 5 December 20th, 2005 08:13 PM
Validation of Form qazi_nomi Javascript 5 August 2nd, 2004 03:49 PM
Form not refreshing after form validation Mimi Javascript How-To 0 August 25th, 2003 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.