<!DOCTYPE html> <html> <head> <title>Opportunity Cost Calculator</title> <head> <body> <style type="text/css"> body{font: 13px Helvetica, "Helvetica Neue", Arial, sans-serif; color: brown;} .text_left{text-align: left} .text_right{text-align: right} .title{text-align: center; padding-bottom: 10px} .font22{font-size: 22px; font-weight: bold} .font20{font-size: 20px; font-weight: bold} .font16{font-size: 16px; font-weight: bold} #lose{font-size: 16px} </style> <table border="0"> <tr><td class="title" colspan="3"><span class="font22">Opportunity Cost Calculator</span><br>How much is being unemployed or under-employed costing you?</td></tr> <tr><td class="font20 text_left" colspan="3">1. Enter your previous (or desired) earnings</td></tr> <tr> <td>Enter EITHER the yearly or hourly rate.</td><td class="text_right">per year -<br>per hour -</td><td><input type="text" name="prev_year" id="prev_year"><br><input type="text" name="prev_hour" id="prev_hour"></td> </tr> <tr><td class="font20 text_left" colspan="3">2. Enter your current earnings</td></tr> <tr> <td>Enter EITHER the yearly or hourly rate.<br>If unemployed, enter 0.</td><td class="text_right">per year -<br>per hour -</td><td><input type="text" name="curr_year" id="curr_year"><br><input type="text" name="curr_hour" id="curr_hour"></td> </tr> <tr><td class="font20 text_left" colspan="3">3. Enter any current unemployment received</td></tr> <tr> <td></td><td class="text_right">per week - </td><td><input type="text" name="week" id="week"></td> </tr> <tr> <td></td><td class="text_right">Total Current Annual Earnings -<br>Total Current Hourly Earnings -</td><td id="total" class="text_right"></td> </tr> <tr><td class="font20 text_left" colspan="3">4. This is how much you are losing...</td></tr> <tr> <td></td><td class="text_right font16">per hour -<br>per day -<br>per month -<br>per year - </td><td id="lose" class="text_right"></td> </tr> </table> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $( "input[type='text']" ).keyup(function(e) { var val = $(this).val(); // delete non digit var key = e.charCode || e.keyCode || 0; if([37,38,39,40].indexOf(key) == -1){ $(this).val(val.replace(/[^0-9\\.]+/g, '')); } // init values var prev_year = parseFloat($('#prev_year').val() || 0); var prev_hour = parseFloat($('#prev_hour').val() || 0); var curr_year = parseFloat($('#curr_year').val() || 0); var curr_hour = parseFloat($('#curr_hour').val() || 0); var week = parseFloat($('#week').val() || 0); var currentAnnual = 0; var currentHourly = 0; var perHour = 0; var perDay = 0; var perMonth = 0; var perYear = 0; // calculate if( (curr_year + curr_hour + week) != 0 ){ if(curr_year != 0){ currentAnnual = curr_year + (week*52) }else{ if(curr_hour != 0){ currentAnnual = (curr_hour*2080) + (week*52) }else{ if(week != 0){ currentAnnual = week*52 } } } } if(currentAnnual != 0){ currentHourly = currentAnnual/2080 } if(prev_year != 0 && currentAnnual != 0){ perYear = prev_year-currentAnnual }else{ if(prev_hour != 0 && currentHourly != 0){ perYear = (prev_hour-currentHourly)*2080 } } if(perYear != 0){ perHour = perYear/2080 perDay = perYear/260 perMonth = perYear/12 } // display $('#total').html(toCurrency(currentAnnual) + '<br>' + toCurrency(currentHourly)); $('#lose').html(toCurrency(perHour) + '<br>' + toCurrency(perDay) + '<br>' + toCurrency(perMonth) + '<br>' + toCurrency(perYear)); }); }); function toCurrency(total){ var total = parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); var round = Math.round(total); if(round > parseFloat(total)){ total = round } return '$' + total; } </script> </body> </html>