[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Calculating Form Fields PHP or JavaScript

Posted on 2008-02-07
3
Medium Priority
?
543 Views
Last Modified: 2008-02-08
Firstly the URL I posted and the associated pages are for testing purposes so please feel free to add entries so I can test your solution.
The URL with the start of what i am trying to work out is:
http://www.wholecaboodle.com.au/selectEvent.php
When you click 'Register" a page with a form will launch. At the bottom of the form the prices for member and non member tickets is displayed next to 2 text fields where the user will add the number of tickets required.
Below this is a total text field.
How do I auto total the No of member ticks x price + No of non-member ticks x price?
Please steer me towards a solution and whether it would be better to code this function in PHP or javaScript

Thanks

Best regards
laurence lewis

0
Comment
Question by:Lewilr9
  • 2
3 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 20840015
so, you want to display the "No of member ticks x price + No of non-member ticks x price" at the bottom...

then you could sum the rows of "No of member ticks x price"  "No of non-member ticks x price"

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 20840038
in the display record set processing itself have temp variable and calculate the sum values of both.. and assign to hidden variable or text field...

hope i am taking you the correct step
0
 
LVL 7

Accepted Solution

by:
shirazti earned 1500 total points
ID: 20849144
I'm not clear enough with your problem. Try this code........ maybe helpful to you
Anyway you need to perform a server validation once the form is submitted.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script language="javascript">
 
var temp1 = 0;
var temp2 = 0;
 
	function doCalculate() {
		
		member = document.getElementById('noTicMem').value;
		nonmember = document.getElementById('noTicNon').value;
		
		
		if(member != '') { 
			member = member * 2;
			temp1 = member; 
		} else { temp1 = 0; }
		
		if(nonmember != '') { 
			nonmember = nonmember * 5;
			temp2 = nonmember; 
		} else { temp2 = 0; }
		
		var total = temp1 + temp2;
		document.getElementById('total').value = total;
	}
 
</script>
</head>
 
<body>
<form id="form1" name="form1" method="post" action="">
<p>noTicMem: <input type="text" name="noTicMem" id="noTicMem" onblur="doCalculate()" />
x2</p>
 
  
 
<p>noTicNonMem:
  <input type="text" name="noTicNon" id="noTicNon" onblur="doCalculate()" /> 
  x5
</p>
<p>Total:
  <input name="total" type="text" id="total" readonly="readonly" />
</p>
 
</form>
</body>
</html>

Open in new window

0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question