codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Multiple form field validation Javascript  Archive Import (Mark) at 15:09 on Thursday, July 03, 2003
 

Hi,
I have a shopping cart page with 8
items, each has a quantity box and drop down
color selection. ONE add to cart button for all items. I`d
like to be able to require color if quantity
is entered and vise versa for each item. I`m
able to prevent submission if no quantity or
color is selected using && but once one item is chosen,
the form will send quantity without color to
check out page. If this makes any sense, help
would be appreciated. Thnaks

Mark

  Re: Multiple form field validation Javascript  Archive Import (david) at 08:07 on Friday, July 04, 2003
 

A few ways you could do this.

One is, when you pull the items into a recordset to build the shopping cart on the page, use the same recordset to build a javascript function - adding a validation line for each item, then call that function when you submit the form.

Make sense?

  Re: Multiple form field validation Javascript  Archive Import (Mark) at 03:08 on Sunday, July 06, 2003
 

Thanks David. Through trial and error and the use of != I finaly got things to work.

  Re: Multiple form field validation Javascript  Archive Import (david) at 06:01 on Sunday, July 06, 2003
 

Using what I suggested or something different? I`m just curious!

  Re: Multiple form field validation Javascript  Archive Import (Mark) at 12:02 on Sunday, July 06, 2003
 

Something different I think. Here`s what I ended up with that seems to do the trick. The first line prevents empty form submission, the following lines check for entries of color and quantity for each fishing lure and will reject if one and not the other is filled in. I`m new to Javascript but, this seems to work in IE, NS 4 and 7.

<SCRIPT LANGUAGE = "JavaScript">

function formCheck()
{
if ((document.theform.VARQuan1.value == "") && (document.theform.AddItem1.selectedIndex==0) && (document.theform.VARQuan2.value == "") && (document.theform.AddItem2.selectedIndex==0) && (document.theform.VARQuan3.value == "") && (document.theform.AddItem3.selectedIndex==0) && (document.theform.VARQuan4.value == "") && (document.theform.AddItem4.selectedIndex==0) && (document.theform.VARQuan5.value == "") && (document.theform.AddItem5.selectedIndex==0) && (document.theform.VARQuan6.value == "") && (document.theform.AddItem6.selectedIndex==0))
{
alert("Please enter a quantity AND color for each item desired");
return false;
}
if (((document.theform.VARQuan1.value != "") && (document.theform.AddItem1.selectedIndex==0))||((document.theform.VARQuan1.value == "") && (document.theform.AddItem1.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 7oz 10/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan2.value != "") && (document.theform.AddItem2.selectedIndex==0))||((document.theform.VARQuan2.value == "") && (document.theform.AddItem2.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 5oz 9/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan3.value != "") && (document.theform.AddItem3.selectedIndex==0))||((document.theform.VARQuan3.value == "") && (document.theform.AddItem3.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 4oz 8/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan4.value != "") && (document.theform.AddItem4.selectedIndex==0))||((document.theform.VARQuan4.value == "") && (document.theform.AddItem4.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 3oz 9/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan5.value != "") && (document.theform.AddItem5.selectedIndex==0))||((document.theform.VARQuan5.value == "") && (document.theform.AddItem5.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 2oz 7/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan6.value != "") && (document.theform.AddItem6.selectedIndex==0))||((document.theform.VARQuan6.value == "") && (document.theform.AddItem6.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 1-1/2oz 6/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan7.value != "") && (document.theform.AddItem7.selectedIndex==0))||((document.theform.VARQuan7.value == "") && (document.theform.AddItem7.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 1oz 5/0 Ruby Lip.");
return false;
}
if (((document.theform.VARQuan8.value != "") && (document.theform.AddItem8.selectedIndex==0))||((document.theform.VARQuan8.value == "") && (document.theform.AddItem8.selectedIndex!=0)))
{
alert("Please enter a quantity AND color for 1/2oz 4/0 Ruby Lip.");
return false;
}
}
</SCRIPT>








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Nested Javascripts
•  ISP says linefeeds are causing problems
•  Linker Error Unresolved External Borland Builder 2006
•  Have multiple ASP.NET web projects share pages and controls
•  Re: How can I read ASCII data file in C++
•  Trouble writing programs
•  Validation Problem
•  Date formating from user input
•  Need help for writing javascript code global empty fields validation


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006