S
Simon Weaver
Hi
There are lots of javascript (quantity, price , total
price etc) order forms on the net available for download
and customisation. Unfortunately, most of them have a
hard-coded price. I am not a java programmer and I am
trying to customise this little script to accommodate a
variable price and extension.
I have 3 columns on my form
The left column (quantity) is enumerated in the script.
Currently the product price is hard-coded in the form
field name.
I have customised the form and added a price column
extended price column. I want to extract the price from
each form field in the price column, formfield names: P1,
P2, P3 etc). And write the extended price to each form
field in the extended price column (formfield names: S1,
S2, S3 etc).
I need to follow the enumeration when refering to my
customised form fields i.e. P
QUESTION: WHAT IS THE SYNTAX FOR ADJOINING THE FORM FIELD
NAME REFERENCE TO THE FOR LOOP NUMERATION? I.E.
item_price = frm.P i .value
Where P is the first letter of the form field name ane i
is the current iteraton
courtesy of http://www.mcfedries.com/JavaScript/
// Run through all the form fields
for (var i=0; i < frm.elements.length; ++i) {
// Get the current field
form_field = frm.elements
// Get the field's name
form_name = form_field.name
// Is it a "product" field?
if (form_name.substring(0,4) == "PROD") {
CUSTOMISED
// extract the price from P i !!!???
item_price = frm.P1.value
// Get the quantity
item_quantity = parseInt(form_field.value)
// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price
CUSTOMISED
frm.S i .value = round_decimals !!!???
(order_total, 2)
}
}
}
// Display the total rounded to two decimal places
frm.TOTAL.value = round_decimals(order_total, 2)
}
FULL CODE EXAMPLE AVAILABLE HERE
http://www.mcfedries.com/JavaScript/OrderTotals.asp
TIA, Simon
There are lots of javascript (quantity, price , total
price etc) order forms on the net available for download
and customisation. Unfortunately, most of them have a
hard-coded price. I am not a java programmer and I am
trying to customise this little script to accommodate a
variable price and extension.
I have 3 columns on my form
The left column (quantity) is enumerated in the script.
Currently the product price is hard-coded in the form
field name.
I have customised the form and added a price column
extended price column. I want to extract the price from
each form field in the price column, formfield names: P1,
P2, P3 etc). And write the extended price to each form
field in the extended price column (formfield names: S1,
S2, S3 etc).
I need to follow the enumeration when refering to my
customised form fields i.e. P
QUESTION: WHAT IS THE SYNTAX FOR ADJOINING THE FORM FIELD
NAME REFERENCE TO THE FOR LOOP NUMERATION? I.E.
item_price = frm.P i .value
Where P is the first letter of the form field name ane i
is the current iteraton
courtesy of http://www.mcfedries.com/JavaScript/
// Run through all the form fields
for (var i=0; i < frm.elements.length; ++i) {
// Get the current field
form_field = frm.elements
// Get the field's name
form_name = form_field.name
// Is it a "product" field?
if (form_name.substring(0,4) == "PROD") {
CUSTOMISED
// extract the price from P i !!!???
item_price = frm.P1.value
// Get the quantity
item_quantity = parseInt(form_field.value)
// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price
CUSTOMISED
frm.S i .value = round_decimals !!!???
(order_total, 2)
}
}
}
// Display the total rounded to two decimal places
frm.TOTAL.value = round_decimals(order_total, 2)
}
FULL CODE EXAMPLE AVAILABLE HERE
http://www.mcfedries.com/JavaScript/OrderTotals.asp
TIA, Simon