I implemented the following function to compute the total value of a form:
$('tr').each(function(index, element) {
if( ($(this).find('input.operation').val() == "add") || ($(this).find('select.operation').val()=="add")) {
total = parseFloat($(this).find('input.subtotal').val( $('input:eq(1)',this).val() * $('input:eq(2)',this).val() ));
console.log(subtotal);
} else {
console.log( $(this).find('input.subtotal').val( $('input:eq(1)',this).val() * $('input:eq(2)',this).val() ) );
}
});
But when I see the console log, it only says:
[prevObject: e.fn.e.init[1].....
instead of showing the actual value, so my question is how do I convert from Object to float?
parseFloat doesn’t seem to be working (obviously because it only converts strings to float)
When you set the value it doesn’t return the actual value, it returns the current jQuery object. Set a variable to the result of
.val()and print that out instead: