I cannot get this code to work. Very simple...I have three list
menus. I want to do a check before the form submits to make sure that
the value of the 3 fields is equal to 12.
Here's my code...
<script language="javas cript">
<!--
function addListValues() {
var grandtotal = 0;
var drop1Value,drop 2Value,drop3Val ue;
var drop1Value=docu ment.cakeForm.i ntQuant1.option s[document.cakeFo rm.intQuant1.op tions.selectedI ndex].value;
var drop2Value=docu ment.cakeForm.i ntQuant2.option s[document.cakeFo rm.intQuant2.op tions.selectedI ndex].value;
var drop3Value=docu ment.cakeForm.i ntQuant3.option s[document.cakeFo rm.intQuant3.op tions.selectedI ndex].value;
grandtotal = (drop1Value-0) + (drop2Value-0) + (drop3Value-0);
if (grandtotal < 12) {
alert( "You do not have enough items selected. You need to choose
12 cheesecakes." );
cakeForm.intQua nt1.focus();
document.cakeFo rm.intQuant1.st yle.background = "#DEAA0C";
return false ;
}
if (grandtotal > 12) {
alert( "You have too many items selected. You need to choose 12
cheesecakes." );
cakeForm.intQua nt1.focus();
document.cakeFo rm.intQuant1.st yle.background = "#DEAA0C";
return false ;
}
if (grandtotal = 12) {
document.cakeFo rm.submit();
//return false ;
}
}
//-->
</script>
Here is one of my three list menus:
<select name="intQuant1 ">
<option value="0">0</option>
<option value="12">12</option>
<option value="4">6</option>
<option value="4">4</option>
</select>
My submit buttonhas this call... onClick="return addListValues() ;
It does not appear to be working for all three list menus.
Many Thanks
menus. I want to do a check before the form submits to make sure that
the value of the 3 fields is equal to 12.
Here's my code...
<script language="javas cript">
<!--
function addListValues() {
var grandtotal = 0;
var drop1Value,drop 2Value,drop3Val ue;
var drop1Value=docu ment.cakeForm.i ntQuant1.option s[document.cakeFo rm.intQuant1.op tions.selectedI ndex].value;
var drop2Value=docu ment.cakeForm.i ntQuant2.option s[document.cakeFo rm.intQuant2.op tions.selectedI ndex].value;
var drop3Value=docu ment.cakeForm.i ntQuant3.option s[document.cakeFo rm.intQuant3.op tions.selectedI ndex].value;
grandtotal = (drop1Value-0) + (drop2Value-0) + (drop3Value-0);
if (grandtotal < 12) {
alert( "You do not have enough items selected. You need to choose
12 cheesecakes." );
cakeForm.intQua nt1.focus();
document.cakeFo rm.intQuant1.st yle.background = "#DEAA0C";
return false ;
}
if (grandtotal > 12) {
alert( "You have too many items selected. You need to choose 12
cheesecakes." );
cakeForm.intQua nt1.focus();
document.cakeFo rm.intQuant1.st yle.background = "#DEAA0C";
return false ;
}
if (grandtotal = 12) {
document.cakeFo rm.submit();
//return false ;
}
}
//-->
</script>
Here is one of my three list menus:
<select name="intQuant1 ">
<option value="0">0</option>
<option value="12">12</option>
<option value="4">6</option>
<option value="4">4</option>
</select>
My submit buttonhas this call... onClick="return addListValues() ;
It does not appear to be working for all three list menus.
Many Thanks
Comment