mercredi 25 février 2015

Having trouble getting javascript to calculate fields

I have tried a couple different ways and I feel like this one is the closest to working, however it is not working. I was hoping that someone could point out and explain what I am doing wrong. I think that parseFloat could be my issue, but I am not sure.



window.onload = function () {
var purchPrice = document.getElementById('purchPrice');
var warrMile = document.getElementById('warrMile');
var currentMile = document.getElementById('currentMile');
var purchMile = document.getElementById('purchMile');
var mileAdjPerct = 0;
var mileAdjEach = 0;
var mileAdjTotal = 0;
}

function warrUpdate() {
var warrPerct = (parseFloat(currentMile.value) - parseFloat(purchMile.value)) / parseFloat(warrMile.value);
var warrEach = parseFloat(purchPrice.value) * warrPerct;
var warrTotal = warrEach * 4;

parseFloat(document.getElementById('mileAdjPerct').value = warrPerct);
parseFloat(document.getElementById('mileAdjEach').value = warrEach);
parseFloat(document.getElementById('mileAdjTotal').value = warrTotal);
}


Here is a fiddle: http://ift.tt/17yJlLS


Aucun commentaire:

Enregistrer un commentaire