Last active
August 29, 2015 14:01
-
-
Save irudoy/aeeb531a6d2bcaac2b5c to your computer and use it in GitHub Desktop.
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
$(document).ready(function(e) { | |
var form = $('#form-converter'); | |
if(form) { | |
form.on('submit', function(e) { | |
var result = '-'; | |
var h = form.find('[data-role="height"]').val(); | |
var w = form.find('[data-role="width"]').val(); | |
var l = form.find('[data-role="length"]').val(); | |
var a = form.find('[data-role="amount"]').val(); | |
var uf = form.find('[data-role="units-from"]').val(); | |
var ut = form.find('[data-role="units-to"]').val(); | |
var rb = form.find('[data-role="result"]'); | |
// u = шт, c = m3, s = m2, m = пог.м | |
if((uf == 'u')&&(ut == 'u')) result = a; | |
if((uf == 's')&&(ut == 'u')) result = 1000000 * a / (w * l); | |
if((uf == 'c')&&(ut == 'u')) result = 1000000000 * a / (h * w * l); | |
if((uf == 'm')&&(ut == 'u')) result = 1000 * a / l; | |
if((uf == 'u')&&(ut == 's')) result = w * l * a / 1000000; | |
if((uf == 's')&&(ut == 's')) result = a; | |
if((uf == 'c')&&(ut == 's')) result = 1000 * a / h; | |
if((uf == 'm')&&(ut == 's')) result = a * w / 1000; | |
if((uf == 'u')&&(ut == 'c')) result = h * w * l * a / 1000000000; | |
if((uf == 's')&&(ut == 'c')) result = h * a / 1000; | |
if((uf == 'c')&&(ut == 'c')) result = a; | |
if((uf == 'm')&&(ut == 'c')) result = h * w * a / 1000000; | |
if((uf == 'u')&&(ut == 'm')) result = l * a / 1000; | |
if((uf == 's')&&(ut == 'm')) result = 1000 * a / w; | |
if((uf == 'c')&&(ut == 'm')) result = 1000000 * a / (h * w ); | |
if((uf == 'm')&&(ut == 'm')) result = a; | |
rb.html(String(parseFloat(result.toFixed(6))) + ' ' + form.find('[data-role="units-to"] > option').filter(':selected').text()); | |
e.preventDefault(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment