Да-да, правильно. Сейчас код приложу.
$(document).ready(function() {
$("select#type").live("change", function() {
var _this = this;
chType(_this);
});
$("select#din").live("change", function() {
var _this = this;
chDin(_this);
});
$("select#diam").live("change", function() {
var _this = this;
chDiam(_this);
//chVes(_this);
});
$("select#length").live("change", function() {
var _this = this;
chLength(_this);
//chVes(_this);
});
$("input#rate").live("change", function() {
var _this = this;
chRate(_this);
});
$("input#ves").live("change", function() {
var _this = this;
chVes(_this);
});
function chType(_this) {
var num = $(_this).attr('class').slice(1);
var type = $(_this).val();
$("select#din.n"+num).load("/ves/function.inc.php", {'action':'din','type':type}, function() {
chDin($("select#din.n"+num));
});
}
function chDin(_this) {
var num = $(_this).attr('class').slice(1);
var din = $(_this).val();
$("select#diam.n"+num).load("/ves/function.inc.php", {'action':'diam','din':din}, function() {
chDiam($("select#diam.n"+num));
});
}
function chDiam(_this) {
var num = $(_this).attr('class').slice(1);
var din = $("select#din.n"+num).val();
var diam = $(_this).val();
$("select#length.n"+num).load("/ves/function.inc.php", {'action':'length','din':din,'diam':diam}, function(data) {
if (data == '0') {
$("select#length.n"+num).attr('disabled','disabled');
//$("input#rate.n"+num).focus();
$.post("/ves/function.inc.php", {'action':'wightnol','din':din,'diam':diam}, function(data) {
$("input#wight.n"+num).val(data);
});
}
else {
$("select#length.n"+num).removeAttr('disabled');
}
chLength($("select#length.n"+num));
});
}
function chLength(_this) {
var num = $(_this).attr('class').slice(1);
var din = $("select#din.n"+num).val();
var diam = $("select#diam.n"+num).val();
var length = $(_this).val();
$.post("/ves/function.inc.php", {'action':'wight','din':din,'diam':diam,'length':length}, function(data) {
$("input#wight.n"+num).val(data);
chRate(_this);
});
}
function chRate(_this) {
var num = $(_this).attr('class').slice(1);
var wight = $("input#wight.n"+num).val();
var rate = $("input#rate.n"+num).val();
var ves = (wight*rate).toFixed(5);
$("input#ves.n"+num).val(ves);
}
function chVes(_this) {
var num = $(_this).attr('class').slice(1);
var wight = $("input#wight.n"+num).val();
var ves = $("input#ves.n"+num).val();
var rate = (ves/wight).toFixed(0);
$("input#rate.n"+num).val(rate);
}
$("button#add").live("click", function() {
var num = $(this).attr('class').slice(1);
var newnum = parseInt(num)+1;
$(this).hide();
$.post("function.inc.php", {'action':'add','num':num}, function(data) {
$("table#calc tbody").append(data);
$("select#type.n"+newnum).focus();
});
if (num>1) {
$("td.n"+num).html('<a class="delrow" href="javascript:void(0)" onclick="del('+num+')"></a>');
}
});
function del(num) {
var row = $("tr.n"+num);
var rowprev = row.prev();
var rownext = row.next().attr('class');
var rowprevnum = parseInt(rowprev.attr('class').slice(1));
row.remove();
if (rowprevnum != '1') {
$('td.n'+rowprevnum).html('<button id="add" class="n'+rowprevnum+'" onclick="return false;"></button><a class="delrow delrowfloat" href="javascript:void(0)" onclick="del('+rowprevnum+')"></a>');
}
else {
if (!rownext) {
$('td.n'+rowprevnum).html('<button id="add" class="n'+rowprevnum+'" onclick="return false;"></button>');
}
}
}