View Full Version : Automatic Calculations

12-27-2006, 08:34 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 a textarea so when they type in a number it calculates the total.

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 type the amount in, say 30 pictures, the calculation will automatically update and show the total price.
(15p*30p = 4.50 obviously)


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>

However, i wish to put another text box, with a different increase value and to also determine the total price value.
How would i go about this?

Thanks in advance,