0

Iam trying to do a calculation. When a user selects a dropdown currency. The system calculates and converts the selected currency from the dropdown to INR currency values. The records are coming from mysql db and the record count will be from one record to 300 records. Here the user needs to change each currency from the drop down and the system converts this selected currency value to INR value. Its really a hectic task. So If the user changes one currency value from dropdown, the system should change the entire row currency value to the selected dropdown value and the system should calculate on certain formulae to change the value to INR. All these is working fine.

Now the issue iam facing is to implement the formulae to the jquery.

Here is the fiddle what i have done:

Fiddle

If you can check the fiddle in the jquery part i have used a formula

 var newTotal = currency==="INR" ? totalINR : (totalINR * conversionRate / row.find('.inrvalue').val()).toFixed(3);

This above formula wrong:

The actual formula iam looking at is

if (currency==="INR")
        {
            var newTotal = totalINR; 
        } else if (currency==="USD")
        {
            var newTotal = (row.find('.total1.').val() *  row.find('.inrvalue').val());
        } else {
            var newTotal = ((row.find('.inrvalue').val() / conversionRate) * row.find('.total1.').val());
        }

How will i change the existing formulae to this? When i implement this formula, iam getting an error Uncaught Error: Syntax error, unrecognized expression: .. Help Appreciated

8
  • Did i complicate the question? Commented Mar 1, 2016 at 8:47
  • what's wrong with the old formula? Commented Mar 1, 2016 at 8:55
  • Instead of the old formula, i need to implement this formula. The old formula calculation is wrong. The new formule which i would implement is as follows: if (currency==="INR") { var newTotal = totalINR; } else if (currency==="USD") { var newTotal = (row.find('.total1.').val() * row.find('.inrvalue').val()); } else { var newTotal = ((row.find('.inrvalue').val() / conversionRate) * row.find('.total1.').val()); } Commented Mar 1, 2016 at 9:00
  • i just want to know of the syntax is correct? Commented Mar 1, 2016 at 9:01
  • 1
    i have edited the question with the formulae i want Commented Mar 1, 2016 at 9:02

1 Answer 1

2

your function is almost right, you have only one "extra" dot after "total1"

you can safely change

 var newTotal = currency==="INR" ? totalINR : (totalINR * conversionRate / row.find('.inrvalue').val()).toFixed(3);

for

var newTotal = 0;
        if (currency==="INR")
        {
            newTotal = totalINR; 
        } else if (currency==="USD")
        {
            newTotal = (row.find('.total1').val() *  row.find('.inrvalue').val());
        } else {
            newTotal = ((row.find('.inrvalue').val() / conversionRate) * row.find('.total1').val());
        }

hope this helps

Sign up to request clarification or add additional context in comments.

2 Comments

Yes it works fine..Thank you. Last question. How will i make newTotal to 3 decimals?
using the same ".toFixed(3)" you were using :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.