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!
function MakeArray(n) {
this.length = n
for (var i=1;i<=n;i ) {this=0}
return this
}
function BuildZeroArray(n) {
this.length = n
for (var i=0;i<=n;i ) {this=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.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 = "?quot; 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"')
}
and.......
for (var rownum=1;rownum<=RowsInForm;rownum ) {
document.write('<tr><td width=192>')
document.write('<img src=http://www.webdeveloper.com/forum/archive/index.php/"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].name)
}
document.write ('</select></td>')
document.write ('<td width=72 align="center"><input class="num"name="qty'
rownum '" value=http://www.webdeveloper.com/forum/archive/index.php/""')
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=http://www.webdeveloper.com/forum/archive/index.php/""')
document.write ('size=10 onfocus="this.blur()"></td>')
document.write ('<td width=120 align="center">')
document.write ('<input class="num" name="extprice' rownum '" value=http://www.webdeveloper.com/forum/archive/index.php/""')
document.write ('size=10 onfocus = "this.blur()"></td>')
document.write ('</tr>')
function MakeArray(n) {
this.length = n
for (var i=1;i<=n;i ) {this=0}
return this
}
function BuildZeroArray(n) {
this.length = n
for (var i=0;i<=n;i ) {this=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.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 = "?quot; 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"')
}
and.......
for (var rownum=1;rownum<=RowsInForm;rownum ) {
document.write('<tr><td width=192>')
document.write('<img src=http://www.webdeveloper.com/forum/archive/index.php/"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].name)
}
document.write ('</select></td>')
document.write ('<td width=72 align="center"><input class="num"name="qty'
rownum '" value=http://www.webdeveloper.com/forum/archive/index.php/""')
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=http://www.webdeveloper.com/forum/archive/index.php/""')
document.write ('size=10 onfocus="this.blur()"></td>')
document.write ('<td width=120 align="center">')
document.write ('<input class="num" name="extprice' rownum '" value=http://www.webdeveloper.com/forum/archive/index.php/""')
document.write ('size=10 onfocus = "this.blur()"></td>')
document.write ('</tr>')