Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

sAVE bUTTON pROBLEM

Locked
at_rcc
Posts: 32
Joined: Thu Sep 02, 2010 11:19 am

sAVE bUTTON pROBLEM

Unread post by at_rcc »

Dear all,
I am having a strange problem with the save button on one of my forms. The save button seems unable to execute when i add the following JavaScript below in the form JavaScript section . Have been unable to find the bug or how to know which line is causing conflict!!

function nuLoadThis() {
calcinv_total();
}

function nuBeforeSave(){

if ( !validateCloseDate() )
return false;

calcinv_total();
return true;
}

function calclinetotal(pthis) {

if (pthis.length == 18) {
// Paramter passed through from tri_product_id
PRE = pthis;

} else {
// Paramter passed through from tri_units or tri_cost
PRE = pthis.name.substring(0,18);
}

//calculate the total of the line by quantity * cost
var unitCost = Number(document.getElementById(PRE+'tri_unit_cost').value);
var total = Number(document.getElementById(PRE+'tri_total').value);
var price = Number(document.getElementById(PRE+'tri_amount').value);

//atish discount part
var discount = Number(document.getElementById(PRE+'tri_discount').value);
discount = (100 - discount)/100;
price = unitCost * discount;
total = price ;

document.getElementById(PRE+'tri_amount').value = price;
document.getElementById(PRE+'tri_total').value = total;

//if the values of the total field is blank then fill them in
if(document.getElementById(PRE+'tri_total').value < '0'){

document.getElementById(PRE+'tri_amount').value = price;
document.getElementById(PRE+'tri_total').value = total;
}

nuFormat(document.getElementById(PRE+'tri_unit_cost'));
nuFormat(document.getElementById(PRE+'tri_total'));
calcinv_total();

}

function calcinv_total() {

//calculate the entire total of all the line totals
var invAmount = Number(0);

var subformToPopulate = 'FMInvoiceItems';
var fieldToPopulate = 'tri_total';
var theList = nuSubformRowArray(subformToPopulate);

for (var i = 0 ; i < theList.length ; i++){
strlength = '0000'+ i;
pstrlength = strlength.length;
PRE = 'FMInvoiceItems' + ('0000'+ i).substring(pstrlength-4);

if (document.getElementById("row"+PRE).checked != 'true') {
var fieldInRow = document.getElementById(theList + fieldToPopulate);
invAmount = invAmount + Number(fieldInRow.value) ;
}else {
invAmount = 0;
}
}//for loop
document.getElementById('tra_amount').value = invAmount;
}//inv total

function getRowPrefixFromLookup(pthis) {
// Needed to update row price totals if user changes a product lookup
PRE = pthis.name.substring(4,22);
nuCreateCookie('row_name_for_transaction_item', PRE, 0);
calclinetotal(nuReadCookie('row_name_for_transaction_item'));
}
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: sAVE bUTTON pROBLEM

Unread post by admin »

at_rcc,

Remove the functions and add them back in one at a time. (and try saving)

Then you will know which one is causing the problem.

Then comment out all the lines in that function and add them back in one at a time. (and try saving)

And you will figure out the problem.

Steven
at_rcc
Posts: 32
Joined: Thu Sep 02, 2010 11:19 am

Re: sAVE bUTTON pROBLEM

Unread post by at_rcc »

Dear Steven,
Thanks for the tip infact the problem was there was no type casting for the variable before it was used for comparison.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: sAVE bUTTON pROBLEM

Unread post by admin »

.
Locked