I'm trying to show an alert if the value of the input (inp_val) isn't between minvalue and maxvalue but it doesn't work, it shows the alert even if the value is between minvalue and 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 the function compare with an onBlur():
echo '<input class="result_fields" autocomplete="off" onBlur="compare(this)" id="result_inp' . $idc . '" type="text" name="test_res' . $idc . '" />'
I've tried to do this in jQuery but is the same error.
Minvalue and maxvalue are input type hidden and its values are stored in a DB on MySQL and retrieved with php like this:
echo '<input type="hidden" value="' . $val_test . '" name="test_name' . $idc . '" id="test_name' . $idc . '" class="testN" />';
The php variable $idc is an incremental function $idc++.
parseInt(x, 10):-P