Mike,
I have pasted my code below. The form works but it is not validating
(checking for the total>14). What am I doing wrong?
Thanks.... Mike
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script language="javascript">
function ValidateForm1()
{
var item1 = Form1.Item1;
var total = Form1.Item1.options[document.Form1.Item1.selectedIndex].value;
total += Form1.Item2.options[document.Form1.Item2.selectedIndex].value;
total += Form1.Item3.options[document.Form1.Item3.selectedIndex].value;
total += Form1.Item4.options[document.Form1.Item4.selectedIndex].value;
total > 14 ? alert("test"); : Form1.Item1.focus();
}
</script>
</head>
<body>
<!--<form method="POST" action="--WEBBOT-SELF--" name="Form1"
onSubmit="location.href='_derived/nortbots.htm';return false;"
webbot-onSubmit> -->
<form method="POST" action="--WEBBOT-SELF--" name="Form1" onSubmit="return
ValidateForm1();">
<!--webbot bot="SaveResults" U-File="_private/form_results.csv"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" startspan --><input TYPE="hidden"
NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" i-checksum="43374"
endspan -->
<p>
<select size="1" name="Item1">
<option value="1">1 Set</option>
<option value="2">2 Sets</option>
<option value="3">3 Sets</option>
<option value="4">4 Sets</option>
</select>
<select size="1" name="Item2">
<option value="1">1 Set</option>
<option value="2">2 Sets</option>
<option value="3">3 Sets</option>
<option value="4">4 Sets</option>
</select>
<select size="1" name="Item3">
<option value="1">1 Set</option>
<option value="2">2 Sets</option>
<option value="3">3 Sets</option>
<option value="4">4 Sets</option>
</select>
<select size="1" name="Item4">
<option value="1">1 Set</option>
<option value="2">2 Sets</option>
<option value="3">3 Sets</option>
<option value="4">4 Sets</option>
</select></p>
<p><input type="submit" value="Submit" name="Submit"><input type="reset"
value="Reset" name="Reset"></p>
</form>
</body>
</html>
MD Websunlimited said:
<select onchange="checkTotal(this.form)" >
<option vaue="1">1</option>
....
</select>
<script language="javascript" >
function checkTotal(theForm) {
var total = theForm.select1.options[theForm.select1.selectedIndex].value;
total += theForm.select2.options[theForm.select2.selectedIndex].value;
total += theForm.select3.options[theForm.select3.selectedIndex].value;
total += theForm.select4.options[theForm.select4.selectedIndex].value;
total > 14 ? alert("The total number of items selected may not exceed 14"); : theForm.select1.focus();
}
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Wish you could calculate form field totals? Well, you can with Form Calculator
http://www.websunlimited.com/order/Product/FormCalc/formcalc.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
I have a form that contains four drop-down boxes, one box each for a specific
item (item1, item2, item3, item4). Each drop-down box has four choices (1, 2,
3, 4). So for each Item, the user can select how many of that item they want,
up to four. For example they can select a quantity of 2 for item1, 3 for
item2, 1 for item3 and 4 for item4. They then click submit.
All that works without a problem. What I want however, is to limit the TOTAL
number of items selected from all four items. They can select 1 through 4 in
each drop-down but I don't want the total number of items to exceed 14. So if
they selected 4 in all four boxes, I would need someway to count this and pop
up a message that says something like "you have exceeded the total items
allowed". I assume this count and validation would need to happen when they
click the Submit button.
How do I do this count and validation.
Thanks... Mike