/    Sign up×
Community /Pin to ProfileBookmark

Trouble Understanding What…..

I am having trouble seeing what each section of my script actually does, could sum1 help me by explaining what each line does? These are the lines I dont understand (see below). I know what they generally do but a quick explanation of what Each line does would be helpful, as I think this would help my learning and Understanding of the language better. Iv also attached my full script if it is required. Thank u in advance!

[code] function MakeArray(n) {
this.length = n
for (var i=1;i<=n;i ) {this[i]=0}
return this
}

function BuildZeroArray(n) {
this.length = n
for (var i=0;i<=n;i ) {this[i]=0}
return this
}

function prodobj(name, unitprice) {
this.name = name
this.unitprice = unitprice
}

function ordobj(prodsub, qty, unitprice, extprice) {
this.prodsub = prodsub
this.qty = qty
this.unitprice = unitprice
this.extprice = extprice
}

function updateRow(rownum) {
ProdSubscript = document.ordform[“prodchosen” rownum].selectedIndex;
var img = new Image();
document.ordform[“prod” rownum].src = imglist[rownum –
1][ProdSubscript].src;
var img = ((document.getElementsByTagName(“img”))[0]);
img.width = imgW;
img.height=imgH;
ordData[rownum].prodsub = ProdSubscript;
tempqty = document.ordform[“qty” rownum].value;
ordData[rownum].qty = tempqty – 0;
ordData[rownum].unitprice = prodlist[rownum-1][ProdSubscript].unitprice;
ordData[rownum].extprice = (ordData[rownum].qty) *
ordData[rownum].unitprice;
document.ordform[“unitprice” rownum].value =
currency(ordData[rownum].unitprice, 10);
document.ordform[“extprice” rownum].value =
currency(ordData[rownum].extprice, 10);
updateTotals();
}

function updateTotals() {
var subtotal = 0
for (var i=1;i<=RowsInForm;i ) {
subtotal=subtotal ordData[i].extprice
}
document.ordform.subtotal.value = currency(subtotal,10)
salestax=0
salestax = SalesTaxRate*subtotal
document.ordform.salestax.value = currency(salestax,10)
document.ordform.grandtotal.value = currency(subtotal salestax,10)
var usTot
eval (‘usTot = (subtotal salestax) * 1.64680’)
document.ordform.usTotal.value = Math.abs((Math.round(usTot*100)/100))
}

function currency(anynum,width) {
anynum=eval(anynum)
workNum=Math.abs((Math.round(anynum*100)/100));workStr=”” workNum
if (workStr.indexOf(“.”)==-1){workStr =”.00″}
dStr=workStr.substr(0,workStr.indexOf(“.”));dNum=dStr-0
pStr=workStr.substr(workStr.indexOf(“.”))
while (pStr.length<3){pStr =”0″}

if (dNum>=1000) {
dLen=dStr.length
dStr=parseInt(“” (dNum/1000)) “,” dStr.substring(dLen-3,dLen)
}

if (dNum>=1000000) {
dLen=dStr.length
dStr=parseInt(“” (dNum/1000000)) “,” dStr.substring(dLen-7,dLen)
}
retval=dStr pStr
if (anynum < 0) {
retval=retval.substring(1,retval.length)
retval=”(” retval “)”
}
retval = “£” retval
while (retval.length<width){retval=” ” retval}

return retval
}

function rBtn() {
for (i=1;i<=RowsInForm;i )
{
eval(‘document.ordform.prod’ i ‘.src = “subscrib.gif”‘)
} [/code]

and…….

[code]
for (var rownum=1;rownum<=RowsInForm;rownum ) {
document.write(‘<tr><td width=192>’)
document.write(‘<img src=”subscrib.gif” name=”prod’ rownum ‘”
align=”left”>’)
document.write(‘<select name=”prodchosen’ rownum ‘”onChange=”updateRow(‘
rownum ‘)”>’)
for (i=0; i<=ProductsInList[rownum-1]; i ) {
document.write (“<option>” prodlist[rownum-1][i].name)
}
document.write (‘</select></td>’)
document.write (‘<td width=72 align=”center”><input class=”num”name=”qty’
rownum ‘” value=””‘)
document.write (‘size=3 onChange=”updateRow(‘ rownum ‘)”></td>’)
document.write (‘<td width=120 height=”99″ align=”center”>’)
document.write (‘<input class=”num” name=”unitprice’ rownum ‘” value=”” ‘)
document.write (‘size=10 onfocus=”this.blur()”></td>’)
document.write (‘<td width=120 align=”center”>’)
document.write (‘<input class=”num” name=”extprice’ rownum ‘” value=”” ‘)
document.write (‘size=10 onfocus = “this.blur()”></td>’)
document.write (‘</tr>’)

[/code]

[upl-file uuid=62c2f872-86f3-47d3-9698-f7205f5c5453 size=35kB]fileddjkchdscdcldkdd.txt[/upl-file]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Makaveli_2003 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.15,
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,
)...