Concatenates instead of adding [duplicate]

-3

Well, I need the variable "_som" to return a sum, instead of concatenating

_eb.addEventListener('click',function(){
    if (_mon > d.v_eleitor){
        var md = _mon - d.v_eleitor;
        k.innerHTML="$"+md+",00";
        _mon = md;
        _jj.innerHTML = d.x_eleitor;
        if (_pp == ""){
            _pp.setAttribute("value", d.x_eleitor);
        } else {
            var yy = _pp.getAttribute("value");
            var _som = eval("yy + 15");
            alert(_som);
            _pp.setAttribute("value", _som);
        }
    } else {
        alert(d._eleitor);
    }
});

I need it to return the sum in the "value" attribute of this progress bar:

<progress id="progress_bar" value="" max="1000">
    
asked by anonymous 02.11.2015 / 23:43

1 answer

2

Sergio has already given you a possible answer to your question. Probably your value is being read as String and therefore can not be added to a inteiro without being converted first.

Change the line:

var _som = eval("yy + 15");

To:

var _som = parseInt(yy, 10) + 15;

Another way is to get the quotes, and put a + before yy :

var _som = eval(+yy + 15);
    
03.11.2015 / 00:52