jquery - value more than not read in if condition in javascript -


i m getting 2 textboxes value 5 , 10.

so m validating them on following if condition

var textboxvalue1 = $('#textboxvalue1' + counter).val(); var textboxvalue2 = $('#textboxvalue2' + counter).val(); if (textboxvalue1 < textboxvalue2) {     alert("error"); } textboxvalue1 = 10 textboxvalue2 = 5 

its showing alert in case.which shud nt show.bt when textboxvalue1 less 10,it works fine.

actually .val() returns string try convert integer use parseint() in context , check.

the parseint() function parses string , returns integer.

note:

the radix parameter used specify numeral system used, example, radix of 16 (hexadecimal) indicates number in string should parsed hexadecimal number decimal number.

if radix parameter omitted, javascript assumes following:

if string begins "0x", radix 16 (hexadecimal) if string begins "0", radix 8 (octal). feature deprecated if string begins other value, radix 10 (decimal)

var textboxvalue1= parseint($('#textboxvalue1'+counter).val(), 10); var textboxvalue2= parseint($('#textboxvalue2'+counter).val(), 10);  if (textboxvalue1 < textboxvalue2) {     alert("error"); } 

Comments