Добрый день, попытаюсь наглядно продемонстрировать код, надеюсь на помощь, спасибо!
Это функция парсинга данных
function parse_answer(data) {
$('#loader').hide();
$('#loader2').hide();
if (data.indexOf('ERROR:') == 0) {
alert(data.replace("ERROR:",""));
return false;
}
else {
var ans = parse_str(data);
$("#account_info_ans").html("<?=lang('ЖЕО ','ЖЭК ')?>" + document.pay.jek.value + "<?=lang(' о/р ',' л/с ')?>" + document.pay.account.value);
$("#period_ans").html(periodstr(ans['period']));
$("#address_ans").html(ans['address']+", КВ."+ans['flat']);
var service_id = parseFloat(ans['service_id']);
var service_title = parseFloat(ans['service_title']);
var service_organization = parseFloat(ans['service_organization']);
var service_accrued_summ = parseFloat(ans['service_accrued_summ']);
var service_debt_summ = parseFloat(ans['service_debt_summ']);
var counter_tariff = parseFloat(ans['counter_tariff']);
var counter_precision = parseFloat(ans['counter_precision']);
$("#counter_number").val(service_id.length);
alert(data); //!!!
var s = '<col width="20%"><col width="20%"><col width="20%"><col width="20%"><col width="20%">';
for (var i = 0; i < service_id.length; i++) {
s += '<tr>';
s += '<td colspan="3" class="text" align="left" style="border-bottom: 1px solid #c0c0c0;">'+service_title[i]+'</td>';
s += '<td colspan="2" class="text" align="right" style="border-bottom: 1px solid #c0c0c0;">'+service_organization[i]+'</td>';
s += '</tr>';
if (service_accrued_summ[i] != '') {
s += '<tr>';
s += '<td colspan="3" class="text" align="left">'+"<?=lang('Нараховано до сплати','Начислено')?>"+'</td>';
s += '<td colspan="2" class="text" align="right" style="font-weight:bold;">' + kop2str(service_accrued_summ[i])+'</td>';
s += '</tr>';
}
else
{
s += '<tr height="8">';
}
var t = 'givc_brd_urdl';
if (counter_tariff[i] != '') {
s += '<tr>';
s += '<td colspan="3" class="givc_txt givc_brd_ur_l" align="center">' + "<?=lang('Показання лiчильникiв','Показания счетчиков')?>"+'</td>';
s += '</tr>';
s += '<tr>';
s += '<td class="givc_txt givc_brd_ur_l" align="center">'+"<?=lang('текущие','поточнi')?>"+'</td>';
s += '<td class="givc_txt givc_brd_ur__" align="center">'+"<?=lang('предыдущие','попереднi')?>"+'</td>';
s += '<td class="givc_txt givc_brd_ur__" align="center">'+"<?=lang('разница','рiзниця')?>"+'</td>';
s += '<td class="givc_txt givc_brd_u___" align="center">'+"<?=lang('тариф','тариф')?>"+'</td>';
s += '<td class="givc_txt givc_brd_ur_l" align="center">'+"<?=lang('к оплате','до сплати')?>"+'</td>';
s += '</tr>';
s += '<tr>';
s += '<td class="givc_in2 givc_brd_urdl" align="center"><input id="counter'+i+'_curr" class="inputbox not_border_input givc_txt" size="6" value="" onInput="recalc_counters('+i+',\'curr\')" onPropertyChange="recalc_counters('+i+',\'curr\')" onKeyUp="recalc_counters('+i+',\'curr\')" onCut="recalc_counters('+i+',\'curr\')" onPaste="recalc_counters('+i+',\'curr\')"></td>';
s += '<td class="givc_in2 givc_brd_urd_" align="center"><input id="counter'+i+'_prev" class="inputbox not_border_input givc_txt" size="6" value="" onInput="recalc_counters('+i+',\'prev\')" onPropertyChange="recalc_counters('+i+',\'prev\')" onKeyUp="recalc_counters('+i+',\'prev\')" onCut="recalc_counters('+i+',\'prev\')" onPaste="recalc_counters('+i+',\'prev\')"></td>';
s += '<td class="givc_in2 givc_brd_urd_" align="center"><input id="counter'+i+'_diff" class="inputbox not_border_input givc_txt" size="6" value="" onInput="recalc_counters('+i+',\'diff\')" onPropertyChange="recalc_counters('+i+',\'diff\')" onKeyUp="recalc_counters('+i+',\'diff\')" onCut="recalc_counters('+i+',\'diff\')" onPaste="recalc_counters('+i+',\'diff\')"></td>';
s += '<td class="givc_in2 givc_brd_u_d_" align="center" style="background-color:#ebebeb;"><input id="counter'+i+'_trff" class="inputbox not_border_input givc_txt" size="6" style="background-color:#ebebeb;" value='+counter_tariff[i]+' readonly></td>';
s += '<td class="givc_in2 givc_brd_urdl" align="center"><input id="counter'+i+'_summ" class="inputbox not_border_input givc_txt" size="8" value="" onInput="recalc_counters('+i+',\'summ\')" onPropertyChange="recalc_counters('+i+',\'summ\')" onKeyUp="recalc_counters('+i+',\'summ\')" onCut="recalc_counters('+i+',\'summ\')" onPaste="recalc_counters('+i+',\'summ\')" style="font-weight:bold;"></td>';
s += '<input type="hidden" id="counter'+i+'_sum2" value="0">';
s += '</tr>';
t = 'givc_brd__rdl';
}
else {
s += '<input type="hidden" id="counter'+i+'_curr" value="">';
s += '<input type="hidden" id="counter'+i+'_prev" value="">';
s += '<input type="hidden" id="counter'+i+'_diff" value="">';
s += '<input type="hidden" id="counter'+i+'_summ" value="">';
s += '<input type="hidden" id="counter'+i+'_sum2" value="0">';
}
var d = "<?=lang('Додатково сплачую','Дополнительно оплачиваю')?>";
if (service_debt_summ[i] > 0) {
d = "<?=lang('Борг ', 'Долг ')?>"+kop2str(service_debt_summ[i])+"<?=lang('. Сплата боргу','. Оплата долга')?>";
}
if (service_debt_summ[i] < 0) {
d = "<?=lang('Переплата ','Переплата ')?>"+kop2str(-service_debt_summ[i])+"<?=lang('. Додатково сплачую','. Дополнительно оплачиваю')?>";
}
s += '<tr>';
s += '<td colspan="4" class="givc_txt" align="right" style="padding-right:8px;">'+d+'</td>';
s += '<td class="givc_in2 '+t+'" align="center"><input id="service'+i+'_add_summ" class="inputbox not_border_input givc_txt" style="font-weight:bold;" size="8" value="" onInput="recalc_summs('+i+')" onPropertyChange="recalc_summs('+i+')" onKeyUp="recalc_summs('+i+')" onCut="recalc_summs('+i+')" onPaste="recalc_summs('+i+')"></td>';
s += '</tr>';
if (i + 1 < service_id.length) {
s += '<tr height="8">';
s += '<td colspan="5" style="border-bottom: 1px solid #0072bc;" />';
s += '</tr>';
s += '<tr height="8" />';
}
s += '<input type="hidden" id="service'+i+'_id" value="'+service_id[i]+'">';
s += '<input type="hidden" id="service'+i+'_accrued_summ" value="'+service_accrued_summ[i]+'">';
s += '<input type="hidden" id="service'+i+'_debt_summ" value="'+service_debt_summ[i]+'">';
s += '<input type="hidden" id="service'+i+'_add_sum2" value="0">';
s += '<input type="hidden" id="counter'+i+'_precision" value="'+counter_precision[i]+'">';
}
$("#services_info").html(s);
alert ($('#service0_add_summ').length);
if (ans['paid_amount'] > 0){
$("#paid_history").show();
$("#paid_history_info").show();
$("#paid_history_info").html(ans['paid_date'] + " " + kop2str(ans['paid_amount']) + " грн.");
}
else{
$("#paid_history").hide();
$("#paid_history_info").hide();
}
hide('verify_block');
show('pay_block');
recalc_summs(0);
}
}
Затем имеем функцию:
function check_digit(name,frac) {
debugger;
if (isNaN(frac)) frac = 0;
if (frac <= 0) frac = -1;
var s = $(name).val();
var i = strpos(s.replace(',','.'),'.'); ----------------------- !!!!!
if (i !== false && i >= 0 && i < s.length-frac-1) {
$(name).val(s.substring(0,i+frac+1));
}
}
var i = strpos(s.replace(',','.'),'.'); -- эта срока кричит об ошибке типа: Uncaught TypeError: Cannot read property 'replace' of undefined
Опять таки дебажим что же храниться в $(name) = #service0_add_summ.
Еще мы имеем функцию:
function recalc_summs(i){
check_digit('#service'+i+'_add_summ',2);
if ($('#service'+i+'_add_summ').val() == '') {
$('#service'+i+'_add_sum2').val('0');
}
else {
var add_summ = $('#service'+i+'_add_summ').val().replace(',','.');
var add_sum2 = '';
var debt_summ = $('#service'+i+'_debt_summ').val(); if (debt_summ == '') debt_summ = 0;
var ok = !isNaN(add_summ) && !isNaN(debt_summ);
if (ok) {
add_sum2 = (add_summ * 100).toFixed(0)*1;
ok = (add_sum2 >= (debt_summ < 0 ? debt_summ : 0));
}
document.getElementById('service'+i+'_add_summ').style.color = ok ? 'black' : 'red';
$('#service'+i+'_add_sum2').val(ok ? add_sum2 : '');
}
var total = 0;
for (var i = 0; i < $('#counter_number').val(); i++) {
var counter_sum2 = $('#counter'+i+'_sum2').val();
var add_sum2 = $('#service'+i+'_add_sum2').val();
var accrued_summ = $('#service'+i+'_accrued_summ').val(); if (accrued_summ == '') accrued_summ = 0;
if (counter_sum2 == '' || add_sum2 == '' || isNaN(accrued_summ)) {
$('#amount').val('');
return;
}
total += counter_sum2*1 + add_sum2*1 + accrued_summ*1;
}
$('#amount').val(kop2str(total));
}
var add_summ = $('#service'+i+'_add_summ').val().replace(',','.');
Как может модифицировать или поправить этот код? Подскажите!
Вот такая задача на мою не профессиональный взгляд все верно, кто заметит буду рад, Спасибо!