I am trying to get the following function to calculate a subtotal by product and then call a calcTotal() function. The input fields are ordered 1 through 6. The field names are price1, qty1, and cost1 and so on for each of the six products. The function is supposed to display the costX amount in the cost
N field. The input parameter of
item is a whole number (integer of 1,2,3,4,5, or 6).
When I hard code the number it works great, when I try to pass the the
item nothing happens.
HELP!
function calcCost(item)
{
// declare variables
var priceX = parseFloat(document.orders.price(item).value);
var qtyX = parseFloat(document.orders.qty(item).value);
var costX = parseFloat(document.orders.cost(item).value);
/* Regular expression for a text string containing 1 or more digits and
no other characters. This expression recongizes integers only. Other
combinations such as 9x, a18, 24-b, 18.2, 24.8 etc. are rejected. */
var reqty = /^\d+$/;
if (reqty.test(document.orders.qty1.value) == false)
{
alert("You must enter qty as a whole number of 0 or more.");
document.orders.qty(item).value == 0;
document.orders.qty(item).focus();
document.orders.qty(item).select();
calcTotal();
}
else
{
costX = (priceX * qtyX).toFixed(2);
document.orders.cost(item).value = costX;
}
calcTotal();
}
-
- function calcCost(item)
- {
- // declare variables
- var priceX = parseFloat(document.orders.price(item).value);
- var qtyX = parseFloat(document.orders.qty(item).value);
- var costX = parseFloat(document.orders.cost(item).value);
-
- /* Regular expression for a text string containing 1 or more digits and
- no other characters. This expression recongizes integers only. Other
- combinations such as 9x, a18, 24-b, 18.2, 24.8 etc. are rejected. */
- var reqty = /^\d+$/;
- if (reqty.test(document.orders.qty1.value) == false)
- {
- alert("You must enter qty as a whole number of 0 or more.");
- document.orders.qty(item).value == 0;
- document.orders.qty(item).focus();
- document.orders.qty(item).select();
- calcTotal();
- }
- else
- {
- costX = (priceX * qtyX).toFixed(2);
- document.orders.cost(item).value = costX;
- }
- calcTotal();
- }
-