JNPW JNPW - 5 months ago 27
jQuery Question

jquery hide/show or condiiton failing

Is there anything wrong with the jQuery/JS below? I have an input field

which on change calls below.
${dAmt} = "10000"
from DB. It basically converts the number to $ format(eg.. 23 to $23.00) and focuses the value to the input field. Issue is the if loop (
if(aAmt >= a_amount)...
) fails.

Even if the condition fails it goes to if loops and shows the
which should not happen. I don't see any error in developers console.

$('#aAmt').change(function() {
var aAmt = $("#aAmt").val();
var a_amount = "${dAmt}";
if(aAmt >= a_amount)


function curFormat(aAmt)
var nAmt = Number(aAmt.replace(/[^0-9\.]+/g,""));
var fAmt = '$' + nAmt.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
document.getElementById("aAmt").value = fAmt;

Also, onSubmit I need to evaluate this aAmt field with a_amount field.

$("#submitId").click(function () {
var aAmt = $("#aAmt").val();
var a_amount = parseInt("${dAmt}");

if ((aAmt >= a_amount) && (pLen.length == 0)) {
alert("Enter ...// ...");
return false;

Here aAmt would be $56.00 for example as it is already converted on click.
a_amount would be = 10000

Added parseInt to a_amount still the if condition fails.


Have you tried to convert a_amount to an int, to be sure to compare two integers together:

var a_amount = parseInt("${dAmt}");