Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating and comparing totals

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
0
0
US
OK, I have this script in an ASP (classic) page

Code:
	<script language="JavaScript" type="text/javascript">
	function calculate(el)
	{
		var form = el.form;
		var xsmall = Number(form.elements["xsmall"].value );
		var small = Number(form.elements["small"].value );
		var medium = Number(form.elements["medium"].value );
		var large = Number(form.elements["large"].value );
		var xlarge = Number(form.elements["xlarge"].value );
		var xxlarge = Number(form.elements["xxlarge"].value );
		var total = xsmall + small + medium + large + xlarge +xxlarge;
		  
		// Check for user entry errors
		if (isNaN(total)) {
			// Alert user of error
			alert("Please enter only numbers");
		} else {
			// Show total in the form field, and select the form field text
			form.elements["total"].value = total;
			//form.elements["total"].select();
		}
	  
	}		
    </script>

which works great. It sums each form field as you go. I also pass in a value in the querystring, called num. Now, I want to warn people that they can't enter a total greater than the number that I have passed in via querystring, so I want to pop up an alert if their total is greater than num, but I am not sure how to do that, so... Any ideas or suggestions how to do this?

Thanks,
Willie
 
Your JS above only sets a form element with the name of Total to your some.

1. You want to prevent them from changing that?

or

2. You want your ASP to check when it processes the form ?

or

3. You want to compare he Total in the form element to the one in the query string before submitting the form?


For 1. set the total element to be read only.

for 2. ask in asp forum.

For 3. We need to know how you are setting the query string.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hmm... perhaps option #2 would be best. I will pursue that route for now. Thanks for helping me clarify, Phil.

wb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top