$(document).ready(function(){ setInterval(calc_all, 1000); }); function calc_all() { var barcode2223 = get_data("barcode2223"); var x,y; if ( barcode2223 ) { x = Math.floor(barcode2223 / 10); y = barcode2223 - x * 10; } var origtime = get_data("origtime"); var curtemperature = get_data("curtemperature"); if ( barcode2223 && origtime && curtemperature ) { var res; if ( curtemperature == 20 ) { res = origtime; } else if ( curtemperature < 20 ) { res = origtime - ( curtemperature - 20 ) * x / 10; } else if ( curtemperature > 20 ) { res = origtime - (curtemperature - 20) * y / 10; } $("#resulttime").html("" + res + " сек."); } else { $("#resulttime").html(""); } } function get_data(id) { var val = $("#" + id).val(); if ( val == "" ) { $("#" + id).css("background", ""); return undefined; } val = val.replace(/,/, "."); val = parseFloat(val); if ( isNaN(val)) { $("#" + id).css("background", "red"); return undefined; } $("#" + id).css("background", ""); return val; }