-2

I am using Javascript. In success function, I am getting some results and storing in var say "baldet" in JS-CODE.

example:

success: function (result) {
        baldet = result;

        console.log(baldet[0].cleavebalance);

        if (openmon == 1){
        $("#clvbalance").val(baldet[0].cleavebalance);
    }
    }

from baldet[0].cleavebalance I am getting 2. My condition is if openmon == 1 then I want to add number 1 in it.

NOTE: add means SUM, not CONCAT()

So that i could get, 2 (from "baldet[0].cleavebalance" + 1 (number i want to add)) i.e. 2 + 1 = 3.

and show in $("#clvbalance").val("3"); // value 3 is after getting SUM RESULT

Currently, I am getting "21" instead of "3"

I hope I made my query clear. Any help will be appreciated.

Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56

1 Answers1

0

You need to parse from string to number like below

console.log("2" + 1); // dose not parse

console.log(parseInt("2") + 1)
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56