Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Automatic Calculations



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
josephman1988



Joined: 27 Dec 2006
Posts: 1

PostPosted: Wed Dec 27, 2006 9:42 pm    Post subject: Automatic Calculations Reply with quote

[QUOTE=josephman1988;1983336]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)


JAVASCRIPT:

Code:
<script>
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;
}
</script>


HTML:

Code:
<form>
<b>Enter number of pictures:</b><br>
<input type="text" onkeyup="validate(this);" name="numPics">
</form>
<br>
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,
regards,
joe.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap