Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

javascript client codes on mvc/razor using elementid

The codes below is extracted from mvc/razor view. but this is more like javascript questions.
Can you take a look the codes and tell me why sometime the total value is calculated wrong in
document.getElementById("feeTotal").value?



<div class="col-md-6">
                                <table width="100%" cellpadding="3" cellspacing="3"> 
                                    <tr style="font-weight:900;">
                                        <td>Fee Description</td>
                                        <td>Unit Price</td>
                                        <td>Qty</td>
                                        <td>Total Cost</td>
                                    </tr>
                                @{
                                    //public List<Domain.FleetFee> FleetFeeList
                                    foreach (Domain.FleetFee item in mh.FleetFeeList("9", "Active"))
                                    {    
                                           <tr>                                        
                                           <td><input type="text" style="text-align:left;font-weight:900;"   readonly id="valueFeeDescription_@item.feeId" value="@item.feeDescription"   /></td>
                                           <td><input type="text" style="text-align:right;font-weight:900;"  readonly id="valueFeeCost_@item.feeId" value="@item.cost" /></td>   
                                           <td><input type="text" style="text-align:right;font-weight:900;"  onchange="CalculatorFeeItem(valueFeeCost_@item.feeId,this,subFeeTotalCost_@item.feeId)" id="Qty_@item.feeId"  /></td>      
                                           <td><input type="text" style="text-align:right;font-weight:900;"  readonly id="subFeeTotalCost_@item.feeId" /></td>                                                                        
                                           </tr>
                                     }
                                }
                                    <tr>
                                        <td colspan="2"><br /></td>
                                        <td style="text-align:right;"></td>
                                        <td><input type="text" style="text-align:right;font-weight:900;"  id="feeTotal" value="0.00" /></td>
                                    </tr>
                                    </table>
                                    <script>
                                        function CalculatorFeeItem(cost, qty, feetotalamount)
                                        {
                                            feetotalamount.value = parseFloat((parseFloat(cost.value) * parseFloat(qty.value))).toFixed(2);                                            
                                            document.getElementById("feeTotal").value = parseFloat(parseFloat(document.getElementById("feeTotal").value) + parseFloat(feetotalamount.value)).toFixed(2);
                                        }
                                    </script>
                            </div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Swatantra Bhargava
Swatantra Bhargava
Flag of India image

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 ITsolutionWizard

ASKER

THE SAME ISSUE IS STILL OCCURRED USING YOUR CODES. THANKS
any helps?
Helps?