View Full Version : Automatic calculations

12-19-2006, 08:55 PM

I've got a site, and working in XHTML Transitional, i've got to a page in which i want to add an automatic calculation which stays fixed on the bottom edge of the window. I've added a form that contains dropdown choices and text areas.

Thorough explanation:
This is a DVD creation business, for personal occasions, business conferenece slideshows, school presentations etc.
For each picture they wish to use will cost them, lets say, 15p, they access the dropdown menu and tick that they want, say 30 pictures, once they select this, the calculation will automatically update and show the total price.
(15p*30p = 4.50 obviously)

Thanks in advance,


12-19-2006, 10:15 PM
It would probably be more efficient to use a simple text box instead of a select element. That way the customer could just enter the number of pictures they need.

function validate(i) {
var total = document.getElementById('total');

if (!i || !i.value) {
total.innerHTML = '0';
return false;

if (isNaN(i.value)) {
total.innerHTML = '0';
document.forms[0].numPics.value = '';
alert('You must enter a valid number.');
return false;

var num = parseInt(i.value)*0.15;
num = num.toFixed(2);
total.innerHTML = ''+num;
return false;
<b>Enter number of pictures:</b><br>
<input type="text" onkeyup="validate(this);" name="numPics">
Your total is: <span id="total">0</span>

12-22-2006, 09:52 PM
Thanks for help .. much more conveniant.

How about if i wish to add another text area, with a different value?