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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with setting up a input to calculate costs of certain products!!

    hi everyone i need some help with javascript
    i have made three prompt boxes asking the customer what product he would like, the price, and the discount. now this is where i get lost, how do i take an input for the quantity of the product required? The message to the customer should say "How many of [product name] would you like?". i will then use the product name variable in place of [product name]. i want these inputs to calculate the cost of my product.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,076
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    PHP Code:
    var productName document.getElementById('ProductName").value;  // unit cost of product
    var productQuan = document.getElementById('
    ProductQuan").value;  // quantity desired
    var productCost = Number(productName) * Number(productQuan);
    document.getElementById('ProductCost').value = productCost.toFixed(2); 
    Might want to add additional checks of input to avoid NaN errors.


  •  

    Posting Permissions

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