|
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
|
|
|
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?
|
|
|
Thanks David. Through trial and error and the use of != I finaly got things to work.
|
|
|
Using what I suggested or something different? I`m just curious!
|
|
|
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>
|
|
|
|
|
|
|
|