here's what I want to do...
I have a pricing table for figuring billing prices.
there are only a couple of fields involved in this table.
"PriceChange" This is the basePrice ofhow much
the price should jump per price change
"Line" This is the CostFactor the number to multiply the basePrice By.
"Fee" This is the final cost for the Line.
Recently they asked to be able to change the price half
way through the table and have the rest of the table reflect the new price.
On a short table like the one below, it's not a problem to manually change
the Fee, but if you have a table that has about 100 price changes
it can get tideous to update all the prices manually.
OK, in comes javascript.
I figured, I'd make a function that on change of the price code
it would figure out the new Fee. then do a for loop to update the rest.
I figured I could make the Document.form.Fee(CostFactor)>value update dynamically.
by creating the value Apt = "document.form.Fee" + CostFactor + ".value"
then the next line be Apt = Fee. This didn't work.
I verified the script works if I hardcode the document.formfee2.value like
document.form.Fee2.value = Fee;
See Below
How can I make the function PriceHandler1 work as described above?
============ CODE BELOW ===========
<HTML>
<HEAD><TITLE>TEST</HEAD>
<SCRIPT Language=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function PriceHandler1(CostFactor,Price)
{
var Fee = CostFactor * Price;
var Apt = "document.form.Fee" + CostFactor + ".value"
Apt = Fee;
alert(ThsMsg);
}
function PriceHandler2(CostFactor,Price)
{
var Fee = CostFactor * Price;
var Apt = "document.form.Fee" + CostFactor + ".value"
document.form.Fee2.value = Fee;
alert(ThsMsg);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="" METHOD=POST NAME="form">
Line 1 <INPUT TYPE=TEXT NAME=PriceChange1 Value="150" onChange="PriceHandler2(1,document.form.PriceChange1.value)"> <INPUT TYPE=TEXT NAME=Fee1 VALUE="150"><BR>
Line 2 <INPUT TYPE=TEXT NAME=PriceChange1 Value="150" onChange="PriceHandler2(2,document.form.PriceChange2.value)"> <INPUT TYPE=TEXT NAME=Fee2 VALUE="300"><BR>
Line 3 <INPUT TYPE=TEXT NAME=PriceChange3 Value="150" onChange="PriceHandler2(3,document.form.PriceChange3.value)"> <INPUT TYPE=TEXT NAME=Fee3 VALUE="450"><BR>
Line 4 <INPUT TYPE=TEXT NAME=PriceChange4 Value="150" onChange="PriceHandler2(4,document.form.PriceChange4.value)"> <INPUT TYPE=TEXT NAME=Fee4 VALUE="600"><BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
I have a pricing table for figuring billing prices.
there are only a couple of fields involved in this table.
"PriceChange" This is the basePrice ofhow much
the price should jump per price change
"Line" This is the CostFactor the number to multiply the basePrice By.
"Fee" This is the final cost for the Line.
Recently they asked to be able to change the price half
way through the table and have the rest of the table reflect the new price.
On a short table like the one below, it's not a problem to manually change
the Fee, but if you have a table that has about 100 price changes
it can get tideous to update all the prices manually.
OK, in comes javascript.
I figured, I'd make a function that on change of the price code
it would figure out the new Fee. then do a for loop to update the rest.
I figured I could make the Document.form.Fee(CostFactor)>value update dynamically.
by creating the value Apt = "document.form.Fee" + CostFactor + ".value"
then the next line be Apt = Fee. This didn't work.
I verified the script works if I hardcode the document.formfee2.value like
document.form.Fee2.value = Fee;
See Below
How can I make the function PriceHandler1 work as described above?
============ CODE BELOW ===========
<HTML>
<HEAD><TITLE>TEST</HEAD>
<SCRIPT Language=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function PriceHandler1(CostFactor,Price)
{
var Fee = CostFactor * Price;
var Apt = "document.form.Fee" + CostFactor + ".value"
Apt = Fee;
alert(ThsMsg);
}
function PriceHandler2(CostFactor,Price)
{
var Fee = CostFactor * Price;
var Apt = "document.form.Fee" + CostFactor + ".value"
document.form.Fee2.value = Fee;
alert(ThsMsg);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="" METHOD=POST NAME="form">
Line 1 <INPUT TYPE=TEXT NAME=PriceChange1 Value="150" onChange="PriceHandler2(1,document.form.PriceChange1.value)"> <INPUT TYPE=TEXT NAME=Fee1 VALUE="150"><BR>
Line 2 <INPUT TYPE=TEXT NAME=PriceChange1 Value="150" onChange="PriceHandler2(2,document.form.PriceChange2.value)"> <INPUT TYPE=TEXT NAME=Fee2 VALUE="300"><BR>
Line 3 <INPUT TYPE=TEXT NAME=PriceChange3 Value="150" onChange="PriceHandler2(3,document.form.PriceChange3.value)"> <INPUT TYPE=TEXT NAME=Fee3 VALUE="450"><BR>
Line 4 <INPUT TYPE=TEXT NAME=PriceChange4 Value="150" onChange="PriceHandler2(4,document.form.PriceChange4.value)"> <INPUT TYPE=TEXT NAME=Fee4 VALUE="600"><BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>