Link to home
Start Free TrialLog in
Avatar of asaworker
asaworker

asked on

ColdFusion cfloop to ASP.NET C# equivalent

I have an old legabcy ColdFsauion site that I am converting into mASP.NET C#. I have a cfloop inside my javascript code that works great. I have to convert that to ASP.NET. Can you do this inline to the page or does it need to be in the .cs file?

An example of the old way:

function CalculateRowTotal(num) {
    var order_total = 0;
      //make all fields for the order form 0 by default for total reasons
      <cfloop from="1" to="15" index="i">
      if(document.po_form.Extended_Cost_#i#.value =="" || document.po_form.Extended_Cost_#i#.value ==null) {
            document.po_form.Extended_Cost_#i#.value=0;
      }      
      if(document.po_form.Unit_Cost_#i#.value =="" || document.po_form.Unit_Cost_#i#.value ==null) {
            document.po_form.Unit_Cost_#i#.value=0;
      }      
      if(document.po_form.Quantity_#i#.value =="" || document.po_form.Quantity_#i#.value ==null) {
            document.po_form.Quantity_#i#.value=0;
      }      
      if(document.po_form.Hidden_Extended_Cost_#i#.value =="" || document.po_form.Hidden_Extended_Cost_#i#.value ==null) {
            document.po_form.Hidden_Extended_Cost_#i#.value=0;
      }      
      if(document.po_form.Inserted_Extended_Cost_#i#.value =="" || document.po_form.Inserted_Extended_Cost_#i#.value ==null) {
            document.po_form.Inserted_Extended_Cost_#i#.value=0;
      }      
      </cfloop>
      
      //again
    // Run through all the form fields

    // Get the current field
    var form_field1 = eval("document.po_form.Unit_Cost_" + num);
      //alert(form_field2);
      var form_field2 = eval("document.po_form.Quantity_" + num);
      var form_field3 = eval("document.po_form.Extended_Cost_" + num);
    var form_field4 = eval("document.po_form.Hidden_Extended_Cost_" + num);
      var form_field5 = eval("document.po_form.Inserted_Extended_Cost_" + num);
    //Get the Unit Cost
    var unit_cost = parseFloat(form_field1.value);
    // Get the Quantity
    var quantity = parseInt(form_field2.value);
      //Get the Extended Cost
      var extendedcost = parseFloat(form_field3.value);
      
      
      
           
      // Update the Extended Cost, Quantity, or Unit Cost
      if ((quantity >= 1 && quantity != "" && quantity !=null) && (unit_cost > 0 && unit_cost != "" && unit_cost !=null)) {
            order_total += quantity * unit_cost;
            form_field3.value = round_decimals(order_total, 2);
            form_field4.value = form_field3.value;
            form_field5.value = form_field3.value;
            //var newValues = addCommas(form_field3.value);
            //form_field3.value = newValues;
            form_field1.value = round_decimals(unit_cost, 5);
            //var newValue = addCommas(form_field5.value);
            //form_field5.value = newValue;
      } else if((quantity >= 1 && quantity != "" && quantity !=null) && (extendedcost > 0 && extendedcost != "" && extendedcost !=null)) {
            order_total += extendedcost / quantity;
            form_field1.value = round_decimals(order_total, 5);
            form_field5.value = extendedcost;
            form_field5.value = round_decimals(extendedcost, 2);
            form_field4.value = form_field5.value
            //var newValues = addCommas(form_field5.value);
            //form_field3.value = newValues;
            //var newValue = addCommas(form_field5.value);
            //form_field5.value = newValue;
      } else if((unit_cost > 0 && unit_cost != "" && unit_cost !=null) && (extendedcost > 0 && extendedcost != "" && extendedcost !=null)) {
            order_total += extendedcost / unit_cost;
            form_field1.value = round_decimals(unit_cost, 5);
            form_field2.value = order_total;
            form_field3.value = extendedcost;
            form_field3.value = round_decimals(extendedcost, 2);
            form_field5.value = form_field3.value
            form_field4.value = form_field5.value
            //var newValue = addCommas(form_field5.value);
            //form_field3.value = newValue;
            //form_field5.value = newValue;
      }
}
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrichmon
mrichmon

Notice that there is no C# or ColdFusion involved anymore....
Avatar of asaworker

ASKER

That worked perfectly thanks...I figured it was betetr to be done in js anyways. I wrote that code 4 years ago.