/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How do I auto-add lines to calling code?

I have created this code (with help from this wonderfull forum), that sums up some salaries and calls the salaries from an array.

There are also some “waiver fees”, and the amount of these can warry from 0 to maybe 15. But my problem is, that if I only add lines to the array, then the calling code will not write everything. But if I add extra empty lines to the calling code, then the salaries wont be summed up.

How do I write this, so that I don’t have to change the calling code constantly, so it matches the input in the array (WaiverObj). The parts Im referring to are posted in bold red types.

In the example below I have added extra lines to the calling code, which results in the salary total of the waivers (WaiverTot) not to be displayed:

[code=php]<html>
<head>
<style type=”text/css”>
.padRt { text-align:right; color:black; }
.padRtR { text-align:right; color:red; }
.rowW { background-color: #FFFFFF; }
.rowB { background-color: #d2e6f9; }
</style>

<title>Salary Summation</title>
<script type=”text/javascript”>
var PlayersObj = [
[‘<b>SPILLER</b>’,'<b>NBA KLUB</b>’,'<b>POS.</b>’,'<b>F&#216;DT</b>’,'<b>&#197;R</b>’,
‘<b>L&#216;N 2008</b>’,'<b>L&#216;N 2009</b>’,'<b>L&#216;N 2010</b>’],
[‘Yao Ming’,’Houston’,’C’,’1980′,’7′,’15070550′,’16378325′,’17686100′],
[‘Emeka Okafor’,’Charlotte’,’PF’,’1982′,’5′,’9537500′,’10538937′,’11540375′],
[‘Paul Millsap’,’Utah’,’PF’,’1985′,’3′,’797581′,”,”],
[‘Caron Butler’,’Washington’,’SF’,’1980′,’7′,’8999980′,’9780970′,’10561960′],
[‘Dorrel Wright’,’Miami’,’SF’,’1985′,’5′,’2900000′,”,”],
[‘Rudy Gay’,’Memphis’,’SG/SF’,’1986′,’3′,’2579400′,’3280996′,”],
[‘Thabo Sefolosha’,’Chicago’,’SG/SF’,’1984′,’3′,’1931160′,’2759627′,”],
[‘Allen Iverson’,’Denver’,’G’,’1975′,’13’,’21937500′,”,”],
[‘Shaun Livingston’,’Miami’,’PG’,’1985′,’5′,’400000′,”,”],
[‘Chris Paul’,’New Orleans’,’PG’,’1985′,’4′,’4574189′,”,”],
[”,”,”,”,”,”,”,”],
[”,”,”,”,”,”,”,”]
];

var WaiverObj = [
[‘<b>SPILLER</b>’,'<b>NBA KLUB</b>’,'<b>POS.</b>’,'<b>F&#216;DT</b>’,'<b>&#197;R</b>’,
‘<b>L&#216;N 2008</b>’,'<b>L&#216;N 2009</b>’,'<b>L&#216;N 2010</b>’],
[‘Shaun Livingston’,’Miami’,’PG’,’1985′,’5′,’400000′,”,”],
[‘Chris Paul’,’New Orleans’,’PG’,’1985′,’4′,’4574189′,”,”]
];

var rdObj = [
[‘<b>SPILLER</b>’,'<b>NBA KLUB</b>’,'<b>POS.</b>’,'<b>F&#216;DT</b>’,'<b>&#197;R</b>’,
‘<b>L&#216;N 2008</b>’,'<b>L&#216;N 2009</b>’,'<b>L&#216;N 2010</b>’],
[‘Eric Gordon’,’L.A. Clippers’,’G’,’1988′,’R’,’2623200′,’2819880′,’3016680′]
];

var SalarySub = [[‘L&#216;N FOR AKTIV ROSTER’,”,”,”,”,’0′,’0′,’0′],[‘L&#216;N FOR AKTIV ROSTER’,”,”,”,”,’0′,’0′,’0′]];
var WaiverTot = [[‘WAIVER FEE’,”,”,”,”,’0′,’0′,’0′],[‘WAIVER FEE’,”,”,”,”,’0′,’0′,’0′]];
var SalaryTot = [[‘SAMLET L&#216;N’,”,”,”,”,’0′,’0′,’0′],[‘SAMLET L&#216;N’,”,”,”,”,’0′,’0′,’0′]];
var SalaryCap = [[‘SALARY CAP’,”,”,”,”,’0′,’0′,’0′],[‘SALARY CAP’ ,”,”,”,”,’70416000′,’70416000′,’70416000′]];
var Capspace = [[‘R&#197;DIGHEDSBEL&#216;B’, ”,”,”,”,’0′,’0′,’0′],[‘R&#197;DIGHEDSBEL&#216;B’ ,”,”,”,”,’0′,’0′,’0′]];

function CalculateSubSalaries() {
SalarySub[0][5] = 0;
SalarySub[0][6] = 0;
SalarySub[0][7] = 0;
for (p=1; p<PlayersObj.length; p++) {
SalarySub[0][5] += Number(PlayersObj[p][5]);
SalarySub[0][6] += Number(PlayersObj[p][6]);
SalarySub[0][7] += Number(PlayersObj[p][7]);
}
}

function CalculateTotWaiver() {
WaiverTot[0][5] = 0;
WaiverTot[0][6] = 0;
WaiverTot[0][7] = 0;
for (p=1; p<WaiverObj.length; p++) {
WaiverTot[0][5] += Number(WaiverObj[p][5]);
WaiverTot[0][6] += Number(WaiverObj[p][6]);
WaiverTot[0][7] += Number(WaiverObj[p][7]);
}
}

function CalculateTotSalaries() {
SalaryTot[0][5] = 0;
SalaryTot[0][6] = 0;
SalaryTot[0][7] = 0;
for (p=1; p<WaiverObj.length; p++) {
SalaryTot[0][5] += Number(WaiverObj[p][5]);
SalaryTot[0][6] += Number(WaiverObj[p][6]);
SalaryTot[0][7] += Number(WaiverObj[p][7]);
}
SalaryTot[0][5] = SalaryTot[0][5]+Number(SalarySub[0][5]);
SalaryTot[0][6] = SalaryTot[0][6]+Number(SalarySub[0][6]);
SalaryTot[0][7] = SalaryTot[0][7]+Number(SalarySub[0][7]);
}

function CalculateSalaryCapspace() {
Capspace[0][5] = 0;
Capspace[0][6] = 0;
Capspace[0][7] = 0;
for (p=1; p<WaiverObj.length; p++) {
Capspace[1][5] += Number(WaiverObj[p][5]);
Capspace[1][6] += Number(WaiverObj[p][6]);
Capspace[1][7] += Number(WaiverObj[p][7]);
}
Capspace[0][5] = SalaryCap[1][5]-Number(SalaryTot[0][5]);
Capspace[0][6] = SalaryCap[1][6]-Number(SalaryTot[0][6]);
Capspace[0][7] = SalaryCap[1][7]-Number(SalaryTot[0][7]);
}

function ShowInfo(RecInfo,posn,flag,InfoType) {
var Info = RecInfo[posn];
var str = ‘<tr class=”rowW”>’;
if (flag) { str = ‘<tr class=”rowB”>’; }
switch (InfoType) {
case “Player”:
var tmp = Info[0].toLowerCase();
tmp = tmp.replace(‘ ‘,’_’);
str += ‘<td><a href=”http://www.nba.com/playerfile/’;
str += tmp+’/index.html”>’;
str += Info[0]+'</a></td>’;
for (var i=1; i<5; i++) { str += ‘<td>’+Info[i]+'</td>’; }
break;
case ‘SalaryCap’:
str += ‘<td><u>’+Info[0]+'</u></td>’;
for (var i=1; i<5; i++) { str += ‘<td><b>’+Info[i]+'</b></td>’; }
break;
case ‘SalarySub’:
case ‘Capspace’:
str += ‘<td><b>’+Info[0]+'</b></td>’;
for (var i=1; i<5; i++) { str += ‘<td><b>’+Info[i]+'</b></td>’; }
break;
default:
str += ‘<td>’+Info[0]+'</td>’;
for (var i=1; i<5; i++) { str += ‘<td>’+Info[i]+'</td>’; }
break;
}
for (var i=5; i<8; i++) {
if (posn == 0) {
if (Info[i] < 0) { str += ‘<td class=”padRtR”>’+Info[i]+'</td>’; }
else { str += ‘<td class=”padRt”>’+Info[i]+'</td>’; }
} else {
if (Info[i] < 0) { str += ‘<td class=”padRtR”>’+addcommas(Info[i])+'</td>’; }
else { str += ‘<td class=”padRt”>’+addcommas(Info[i])+'</td>’; }
}
}
str += ‘</tr>’;
return str;
}

function addcommas( sValue ) {
var sRegExp = new RegExp(‘(-?[0-9]+)([0-9]{3})’);
while(sRegExp.test(sValue)) {
sValue = sValue.replace(sRegExp, ‘$1.$2’);
}
return sValue;
}

</script>
</head>
<body>

<center>
<table width=”750″>

<colgroup span=”8″>
<col span=”1″ style=”width:22&#37;;” />
<col span=”1″ style=”width:15%;” />
<col span=”3″ style=”width:7%;” />
<col span=”3″ style=”width:14%;” />
</colgroup>

<tr bgcolor=”d2e6f9″>
<th colspan=”8″><h3>ROSTER</h3></td>
</tr>

<script type=”text/javascript”>
var t = true; var f = false;
CalculateSubSalaries();
CalculateTotWaiver();
CalculateTotSalaries();
CalculateSalaryCapspace();
document.write(ShowInfo(PlayersObj,0,f,”));

document.write(ShowInfo(PlayersObj,1,t, ‘Player’));
document.write(ShowInfo(PlayersObj,2,f, ‘Player’));
document.write(ShowInfo(PlayersObj,3,t, ‘Player’));
document.write(ShowInfo(PlayersObj,4,f, ‘Player’));
document.write(ShowInfo(PlayersObj,5,t, ‘Player’));
document.write(ShowInfo(PlayersObj,6,f, ‘Player’));
document.write(ShowInfo(PlayersObj,7,t, ‘Player’));
document.write(ShowInfo(PlayersObj,8,f, ‘Player’));
document.write(ShowInfo(PlayersObj,9,t, ‘Player’));
document.write(ShowInfo(PlayersObj,10,f,’Player’));
document.write(ShowInfo(PlayersObj,11,t,’Player’));
document.write(ShowInfo(PlayersObj,12,f,’Player’));

document.write(ShowInfo(SalarySub,0,f, ‘SalarySub’));
document.write(ShowInfo(WaiverTot,0,f, ‘WaiverTot’));
document.write(ShowInfo(SalaryTot,0,t, ‘SalaryTot’));
document.write(ShowInfo(SalaryCap,1,f, ‘SalaryCap’));
document.write(ShowInfo(Capspace,0,t, ‘Capspace’));

</script>
</table>

<br><br>

<table width=”750″>

<colgroup span=”8″>
<col span=”1″ style=”width:22%;” />
<col span=”1″ style=”width:15%;” />
<col span=”3″ style=”width:7%;” />
<col span=”3″ style=”width:14%;” />
</colgroup>

<tr bgcolor=”d2e6f9″>
<th colspan=”8″><h3>WAIVERS</h3></td>
</tr>

<script type=”text/javascript”>
CalculateTotWaiver();
document.write(ShowInfo(WaiverObj,0,f));
document.write(ShowInfo(WaiverObj,1,f));
document.write(ShowInfo(WaiverObj,2,f));
document.write(ShowInfo(WaiverObj,3,f));
document.write(ShowInfo(WaiverObj,4,f));
document.write(ShowInfo(WaiverObj,5,f));
document.write(ShowInfo(WaiverTot,0,t));
</script>
</table>

<br><br>

<table width=”750″>

<colgroup span=”8″>
<col span=”1″ style=”width:22%;” />
<col span=”1″ style=”width:15%;” />
<col span=”3″ style=”width:7%;” />
<col span=”3″ style=”width:14%;” />
</colgroup>

<tr bgcolor=”d2e6f9″>
<th colspan=”8″><h3>ROSTER DEVELOPMENT PLAYER</h3></td>
</tr>

<script type=”text/javascript”>
CalculateTotWaiver();
document.write(ShowInfo(rdObj,0,f));
document.write(ShowInfo(rdObj,1,f));
</script>

</table>
</center> [/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NRAauthorOct 30.2008 — OK... it took a while. But I figured it out. Case closed ?

[code=php]<script type="text/javascript">
var t = true; var f = false;
CalculateTotWaiver();
document.write(ShowInfo(WaiverObj,0,f));
for (p=1; p<WaiverObj.length; p++) {
document.write(ShowInfo(WaiverObj,p,f,'Player'));
}
document.write(ShowInfo(WaiverTot,0,t));
</script> [/code]
×

Success!

Help @NRA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...