jquery - javascript If statement not working -


i'm trying show alert if value of input (inp_val) isn't between minvalue , maxvalue doesn't work, shows alert if value between minvalue , maxvalue.

function compare(e){     this_id = e.id.slice(10,15);     inp_val = e.value;     minvalue = document.getelementbyid('min_' + this_id).value;     maxvalue = document.getelementbyid('max_' + this_id).value;     console.log(maxvalue);     console.log(minvalue);     console.log(inp_val);     if(inp_val < minvalue){         alert('minimum value: ' + minvalue + 'input value: ' + inp_val);     }     if(inp_val > maxvalue){         alert('maximum value: ' + maxvalue + ' input value: ' + inp_val);     } } 

i'm calling function compare onblur():

echo '<input class="result_fields" autocomplete="off" onblur="compare(this)" id="result_inp' . $idc . '" type="text" name="test_res' . $idc . '" />' 

i've tried in jquery same error. minvalue , maxvalue input type hidden , values stored in db on mysql , retrieved php this:

echo '<input type="hidden" value="' . $val_test . '" name="test_name' . $idc . '" id="test_name' . $idc . '" class="testn" />'; 

the php variable $idc incremental function $idc++.

you need parse integers or floats values text box

if integers:

minvalue = document.getelementbyid('min_' + this_id).value; maxvalue = document.getelementbyid('max_' + this_id).value; minvalue = parseint(minvalue,10); maxvalue = parseint(maxvalue,10); 

or if floats:

minvalue = document.getelementbyid('min_' + this_id).value; maxvalue = document.getelementbyid('max_' + this_id).value; minvalue = parsefloat(minvalue); maxvalue = parsefloat(maxvalue); 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -