Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatic calculations

    Hello,

    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,

    Regards,
    Joe

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    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>
    <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>
    Last edited by j9ine; 12-19-2006 at 11:32 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for help .. much more conveniant.

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •