mercredi 25 mars 2015

Angular JS calculation based on input boxes

I read this thread: Simple Percentage Calculation of an Input Field with JQuery


But can't seem to get it to work for my situation. I have two input boxes, Wholesale and Sell Price, and I want to calculate the markup (difference) on the fly as the user is changing their Sell Price. I've built a simplified version of what I'm trying to do here:


http://ift.tt/1BkZbSy


And below is the JS - can anyone see what I'm doing wrong? Thanks!!





$(function() {

// cache elements that are used at least twice
var $sellprice = $("#SellPrice"),
$markup = $("#markup"),
$wholesale = $("#wholesale");

// attach handler to input keydown event
$sellprice.keyup(function(e){
if (e.which == 13) {
return;
}
var sellprice = parseFloat($sellprice.val()),
markup = sellprice-wholesale;

if (isNaN(sellprice)) {
$markup.hide();
return;
}
else {

$markup.fadeIn().text(markup.toFixed(2));


}
});

});



Aucun commentaire:

Enregistrer un commentaire