0

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..

2
  • I bet you're getting NaN instead of the expected result. Commented Sep 27, 2013 at 7:11
  • Based on the title of your question, I'm assuming you expect the two textfields to contain numbers. Is that correct? Commented Sep 27, 2013 at 7:13

2 Answers 2

1

How about:

var outoff11 = parseInt(document.getElementById('out_off11').value, 10);
var acc11 = parseInt(document.getElementById('acc11').value, 10);
Sign up to request clarification or add additional context in comments.

2 Comments

It is working for me.. Please tell me why you have used (value,10) in the last.
Well, that's not really necessary, but it just defines the numeric system you want the integer to be parsed as (you want decimal numbers, right?). 2 stands for binary, 10 stands for decimal and so on.
1

Change

var temp = acc11 <= outoff11;

to

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

2 Comments

This should solve the problem, but generally, it would be best to keep the int value, for later use without similar confusion, right?
I'm not sure what he's trying to accomplish but if there are no further manipulations on this, then this should be sufficient.

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.