View Full Version : need help with setting up a input to calculate costs of certain products!!

10-09-2008, 05:31 PM
hi everyone i need some help with javascript:o
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.

10-09-2008, 07:30 PM
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.