gregp
12-05-2006, 01:56 AM
Hi,
I've got an orderform which uses javascript to run client-side calculations, and php to process the form. It's a three-stage system which has display, confirm / modify and process stages. Presently at http://www.eleceng.adelaide.edu.au/training/php/orderform_sp5.php
So the user enters what they want and the javascript calculates the total. User clicks Review, reviews the info and then decides they want to enter something else. When they get taken back to the first page, the fields on the order table are all populated, BUT... if a new row is entered, the grand total resets to zero.
Inspecting the JS, I can see why; when the js is executed, ordobj is created with zeros for the unit cost, total and quantity. I.e.:
ordData = new MakeArray(RowsInForm)
for (var i=1; i<= RowsInForm; i++) {
ordData[i] = new ordobj(0,0,0)
}
function ordobj(Qty, Unit_Cost, Line_Total) {
this.Qty = Qty
this.Unit_Cost = Unit_Cost
this.Line_Total = Line_Total
}
So what I need to do is populate ordobj with the variables entered by the user rather than a string of zeros, i.e. the values stored in $_POST so the grand total starts off at the correct value.
The fields in the order table are named Qty1, Unit_Cost1, Line_Total1, Qty2, Unit_Cost2, Line_Total2 etc for as many rows as are entered. So I can't just have the variable name hard-coded like:
for (var i=1; i<= RowsInForm; i++) {
var newqty = '<?=$_POST['Qty1']?>';
ordData[i] = new ordobj(newqty,....)
}
because the actual PHP field name needs to be based on the value of i in the loop. E.g. var newqty = '<?=$_POST['Qty'+i+'']?>'; which doesn't work because that literal value doesn't exist.
I then thought of getting the value of i, writing it to a php variable, and then using that within the above statement, e.g.
<?=$currentrow?> = 'Qty'+i
var newqty = '<?=$_POST[$currentrow]?>';
No luck.
var qty = 'Qty'+i
var jqty = '<?=$_POST[qty]?>';
No luck either.
I think I'm at the limits of my js and php knowledge, and I don't have much hair left that can be torn out! I'm sure it's just a syntax thing; can anyone help with this?
Thanks in anticipation!
Greg
I've got an orderform which uses javascript to run client-side calculations, and php to process the form. It's a three-stage system which has display, confirm / modify and process stages. Presently at http://www.eleceng.adelaide.edu.au/training/php/orderform_sp5.php
So the user enters what they want and the javascript calculates the total. User clicks Review, reviews the info and then decides they want to enter something else. When they get taken back to the first page, the fields on the order table are all populated, BUT... if a new row is entered, the grand total resets to zero.
Inspecting the JS, I can see why; when the js is executed, ordobj is created with zeros for the unit cost, total and quantity. I.e.:
ordData = new MakeArray(RowsInForm)
for (var i=1; i<= RowsInForm; i++) {
ordData[i] = new ordobj(0,0,0)
}
function ordobj(Qty, Unit_Cost, Line_Total) {
this.Qty = Qty
this.Unit_Cost = Unit_Cost
this.Line_Total = Line_Total
}
So what I need to do is populate ordobj with the variables entered by the user rather than a string of zeros, i.e. the values stored in $_POST so the grand total starts off at the correct value.
The fields in the order table are named Qty1, Unit_Cost1, Line_Total1, Qty2, Unit_Cost2, Line_Total2 etc for as many rows as are entered. So I can't just have the variable name hard-coded like:
for (var i=1; i<= RowsInForm; i++) {
var newqty = '<?=$_POST['Qty1']?>';
ordData[i] = new ordobj(newqty,....)
}
because the actual PHP field name needs to be based on the value of i in the loop. E.g. var newqty = '<?=$_POST['Qty'+i+'']?>'; which doesn't work because that literal value doesn't exist.
I then thought of getting the value of i, writing it to a php variable, and then using that within the above statement, e.g.
<?=$currentrow?> = 'Qty'+i
var newqty = '<?=$_POST[$currentrow]?>';
No luck.
var qty = 'Qty'+i
var jqty = '<?=$_POST[qty]?>';
No luck either.
I think I'm at the limits of my js and php knowledge, and I don't have much hair left that can be torn out! I'm sure it's just a syntax thing; can anyone help with this?
Thanks in anticipation!
Greg