Javascript compare not working -


i have condition in javascript below

function check() {     var amount = document.getelementbyid('pamount').value;     var quantity = document.getelementbyid('qty').value;     var pmin = document.getelementbyid('pmin').value;     var pmax = document.getelementbyid('pmax').value;     var stock = document.getelementbyid('stocks').value;      if (amount > pmax) {         alert('price should not more maximum price');         return false;     }     if (amount < pmin) {         alert('price should not less minimum price');         return false;     }     if (quantity > stock) {         alert('please enter quantity no more maximum');         return false;     }     if (quantity < 1) {         alert('please enter valid quantity');         return false;     } } 

and here html fields

<input type="text" value=""  data-toggle="tooltip" data-placement="top" class="form-control small qty_box" id="qty" name="qty"> <input style="width:90px; float:left" type="text" value="" class="form-control small" id="pmin" name="min"> <input style="width:90px; float:left" type="text" class="form-control small" id="pmax" name="max"> 

but return false. when enter less value amount alerts same. tried alerting amount , pmax. gets actual value. wrong compare gave amount 75 , pmax 100.

use parsefloat() or parseint() per need compare numbers. below code used parsefloat().

    var amount = parsefloat(document.getelementbyid('pamount').value);     var quantity = parsefloat(document.getelementbyid('qty').value));     var pmin = parsefloat(parsefloat(document.getelementbyid('pmin').value);     var pmax = parsefloat(document.getelementbyid('pmax').value);     var stock = parsefloat(document.getelementbyid('stocks').value); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -