Julien698 Julien698 - 4 months ago 4x
Javascript Question

It is possible to use eval to test an equality?

I try to get a boolean return from a simple condition. it is possible to use Eval function to do that or may I have to use a if statement ?

here is my expression :

alert(eval($("#val1").val() + $("#val2").val() == $("#result1").val()));

It's numeric values like 1 + 1 = 2 // true

hsh hsh

You should pars them to numbers like this:

alert(Number($("#val1").val()) + Number($("#val2").val()) ==  Number($("#result1").val()) );

if you don't pars them to numbers,java-script assumes they are strings and does a concatenation, and then val1(1) + val2(1) = 11