Indudhara Gs
Indudhara Gs

Reputation: 11

compare 2 variables having number in javascript

Below is my code which I am using.. Here I am getting values from form elements. Please guide me through it.. It is not giving proper result.

var outoff11 = document.getElementById('out_off11').value;
var acc11 = document.getElementById('acc11').value;
var temp = acc11 <= outoff11;
if(temp){
alert("True");
alert(outoff+acc);
}
    else{
            alert("False");
            alert(outoff+acc);
        }

Thanks in advance..

Upvotes: 0

Views: 94

Answers (2)

Aashray
Aashray

Reputation: 2753

Change

var temp = acc11 <= outoff11;

to

var temp = parseInt(acc11,10) <= parseInt(outoff11,10);

Upvotes: 1

mavrosxristoforos
mavrosxristoforos

Reputation: 3643

How about:

var outoff11 = parseInt(document.getElementById('out_off11').value, 10);
var acc11 = parseInt(document.getElementById('acc11').value, 10);

Upvotes: 1

Related Questions