0

Im having a terrible time trying to calculate the value of two form fields. I'm constantly getting "NAN" which would indicate non-numeric input, this is despite the fact that the form fields are only populated with numbers.

In response I tried to use ParseInt to get a numeric value. This also fails to yield a successful result.

This is what I have so far. Any help is appreciated.

$('#value-calc input').change(function () {

    var valueINT = parseInt($('#value'),10);
    var quantINT = parseInt($('#quantity'), 10);
    var math = ((valueINT/quantINT)*1000);

    $('#cpm').val(math);
});

http://jsfiddle.net/greyoxide/YRWAA/1/

3 Answers 3

1

You need to add the .val() method after your selectors to get the value they hold

working fiddle

Sign up to request clarification or add additional context in comments.

Comments

1

You're not passing in strings when you refer to elements by ID with that jQuery.

Perhaps try $('#value').val() in the parseInt methods instead.

1 Comment

Thanks I didnt understand that I needed to qualify the input.
0

Try this:

$('#value-calc input').keyup(function () {

var valueINT = $('#value').val();
var quantINT = $('#quantity').val();
var math = ((valueINT/quantINT)*1000);
$('#cpm').val(math);

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.