Created
May 10, 2012 16:34
-
-
Save kyranjamie/2654337 to your computer and use it in GitHub Desktop.
jQuery - Calculate inputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var week = $('.week'); | |
var month= $('.month'); | |
var year = $('.year'); | |
function weekCalc(sender, args) { | |
var value = sender.val(); | |
var milesPerMonth = value * 4.35; | |
var milesPerYear = value * 52; | |
month.val(Math.round(milesPerMonth)); | |
year.val(Math.round(milesPerYear)); | |
} | |
function monthCalc(sender, args) { | |
var value = sender.val(); | |
var milesPerWeek = value / 4.35; | |
var milesPerYear = value * 12; | |
week.val(Math.round(milesPerWeek)); | |
year.val(Math.round(milesPerYear)); | |
} | |
function yearCalc(sender, args) { | |
var value = sender.val(); | |
var milesPerWeek = value / 52; | |
var milesPerMonth = value / 12; | |
week.val(Math.round(milesPerWeek)); | |
month.val(Math.round(milesPerMonth)); | |
} | |
week.change(function () { | |
weekCalc($(this)); | |
}); | |
week.keyup(function () { | |
weekCalc($(this)); | |
}).keyup(); | |
month.change(function () { | |
monthCalc($(this)); | |
}); | |
month.keyup(function () { | |
monthCalc($(this)); | |
}).keyup(); | |
year.change(function () { | |
yearCalc($(this)); | |
}); | |
year.keyup(function () { | |
yearCalc($(this)); | |
}).keyup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment