Hi guys, can anyone help with adding comments in this codes, im still new in this field and im trying hard to learn through whatever media i can get.Thanks 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){
var exeLine='ProdSubscript=document.ordform.prodchosen'+rownum+'.selectedIndex'
eval(exeLine);
ordData[rownum].prodsub=ProdSubscript;
var exeLine='tempqty=document.ordform.qty'+rownum+'.value'
eval(exeLine);
ordData[rownum].qty=tempqty-0 //-- Gets unit price from the product price list.
ordData[rownum].unitprice=prodlist[ProdSubscript].unitprice
ordData[rownum].extprice=(ordData[rownum].qty)*ordData[rownum].unitprice
var exeLine='document.ordform.unitprice'+rownum+'.value=currency(ordData['+rownum+'].unitprice,10)'
eval (exeLine)
var exeLine='document.ordform.extprice'+rownum+'.value=currency(ordData['+rownum+'].extprice,10)'
eval(exeLine);
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
if (document.ordform.Taxable.checked) {
salestax = SalesTaxRate*subtotal;
}
document.ordform.salestax.value = currency(salestax,10);
document.ordform.grandtotal.value = currency(subtotal+salestax,10);
}
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 = "R"+retval
//--Pad with leading blanks to better align numbers.
while (retval.length<width){retval=" "+retval}
return retval;
}
</script>
</head>
<body>
<h2><b><center>Ligwalagwala Order Form</center></b></h2>
<div id="navbar" style="text-align:center;">
<p><a href="Ligwalagwalafunerals.html">Home</a> | <a href="services.html">Services</a> | <a href="orderform.html">Order Form</a> | <a href="contacts.html">Contact Us</a><br /></div>
</p>
<table border="0">
<tr>
<h3><b>Complete the form below</b></h3>
<p>Name<br />
<input type="text" name="name" size="40" /></p>
<p>Surname<br />
<input type="text" name="surname" size="40" /></p>
<p>Residential Address<br />
<input type="text" name="residential_address" size="60" /></p>
<input type="text" name="name" size="60" /></p>
<input type="text" name="name" size="60" /></p>
<p>Code<input type="text" name="code" size="10" onchange="return checkForNumber(this.value);"/></p>
<p>Contact Number<br />
<input type="text" name="area_code" size="3" maxlength="3" onchange="return checkForNumber(this.value);" />
<input type="text" name="number" size="7" maxlength="7" onchange="return checkForNumber(this.value);" /></P>
<p>Cellphone<br />
<input type="text" name="cellnumber" size="10" maxlength="10" onchange="return checkForNumber(this.value);" /></p>
<p>Email Address<br />
<input type="text" name="email" size="50" /></P>
</tr></table>
<script type="text/JavaScript">
prodlist = new BuildZeroArray(ProductsInList);
prodlist[0] = new prodobj('Please choose',0);
prodlist[1] = new prodobj('Funeral Coffin Basic',750.00);
prodlist[2] = new prodobj('Funeral Coffin Basic 2',1500.50);
prodlist[3] = new prodobj('Casket Basic',5000.00);
prodlist[4] = new prodobj('Casket Basic 2',10000.00);
prodlist[5] = new prodobj('Full Funeral Basic 1',5000.00);
prodlist[6] = new prodobj('Full Funeral Basic 2',7500.00)
prodlist[7] = new prodobj('Full Funeral Basic 3',10000.00);
prodlist[8] = new prodobj('Body Storaage per day',100.00);
prodlist[9] = new prodobj('Tent Chairs Hire',1000.00);
prodlist[10] = new prodobj('Grave Arrangement',550.00);
ordData = new MakeArray(RowsInForm);
for (var i=1; i<= RowsInForm; i++) {
ordData = new ordobj(0,0,0,0);
}
</script>
</p>
<form name="ordform" method="post" action="someHandler">
<table align="center" border="1"><tr>
<th width="192" <b>Product</b></th>
<th width="72" align="center"><b>Qty</b></th>
<th width="120" align="center"><b>Unit Price</b></th>
<th width="120" align="center"><b>Ext Price</b></th>
</tr>
<script type="text/JavaScript">
for (var rownum=1;rownum<=RowsInForm;rownum++) {
document.write('<tr><td width=192 >');
document.write('<select name="prodchosen'+rownum+'" onChange="updateRow('+rownum+')">');
for (i=0; i<=ProductsInList; i++) {
document.write ("<option>"+prodlist.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 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>');
}
</script>
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){
var exeLine='ProdSubscript=document.ordform.prodchosen'+rownum+'.selectedIndex'
eval(exeLine);
ordData[rownum].prodsub=ProdSubscript;
var exeLine='tempqty=document.ordform.qty'+rownum+'.value'
eval(exeLine);
ordData[rownum].qty=tempqty-0 //-- Gets unit price from the product price list.
ordData[rownum].unitprice=prodlist[ProdSubscript].unitprice
ordData[rownum].extprice=(ordData[rownum].qty)*ordData[rownum].unitprice
var exeLine='document.ordform.unitprice'+rownum+'.value=currency(ordData['+rownum+'].unitprice,10)'
eval (exeLine)
var exeLine='document.ordform.extprice'+rownum+'.value=currency(ordData['+rownum+'].extprice,10)'
eval(exeLine);
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
if (document.ordform.Taxable.checked) {
salestax = SalesTaxRate*subtotal;
}
document.ordform.salestax.value = currency(salestax,10);
document.ordform.grandtotal.value = currency(subtotal+salestax,10);
}
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 = "R"+retval
//--Pad with leading blanks to better align numbers.
while (retval.length<width){retval=" "+retval}
return retval;
}
</script>
</head>
<body>
<h2><b><center>Ligwalagwala Order Form</center></b></h2>
<div id="navbar" style="text-align:center;">
<p><a href="Ligwalagwalafunerals.html">Home</a> | <a href="services.html">Services</a> | <a href="orderform.html">Order Form</a> | <a href="contacts.html">Contact Us</a><br /></div>
</p>
<table border="0">
<tr>
<h3><b>Complete the form below</b></h3>
<p>Name<br />
<input type="text" name="name" size="40" /></p>
<p>Surname<br />
<input type="text" name="surname" size="40" /></p>
<p>Residential Address<br />
<input type="text" name="residential_address" size="60" /></p>
<input type="text" name="name" size="60" /></p>
<input type="text" name="name" size="60" /></p>
<p>Code<input type="text" name="code" size="10" onchange="return checkForNumber(this.value);"/></p>
<p>Contact Number<br />
<input type="text" name="area_code" size="3" maxlength="3" onchange="return checkForNumber(this.value);" />
<input type="text" name="number" size="7" maxlength="7" onchange="return checkForNumber(this.value);" /></P>
<p>Cellphone<br />
<input type="text" name="cellnumber" size="10" maxlength="10" onchange="return checkForNumber(this.value);" /></p>
<p>Email Address<br />
<input type="text" name="email" size="50" /></P>
</tr></table>
<script type="text/JavaScript">
prodlist = new BuildZeroArray(ProductsInList);
prodlist[0] = new prodobj('Please choose',0);
prodlist[1] = new prodobj('Funeral Coffin Basic',750.00);
prodlist[2] = new prodobj('Funeral Coffin Basic 2',1500.50);
prodlist[3] = new prodobj('Casket Basic',5000.00);
prodlist[4] = new prodobj('Casket Basic 2',10000.00);
prodlist[5] = new prodobj('Full Funeral Basic 1',5000.00);
prodlist[6] = new prodobj('Full Funeral Basic 2',7500.00)
prodlist[7] = new prodobj('Full Funeral Basic 3',10000.00);
prodlist[8] = new prodobj('Body Storaage per day',100.00);
prodlist[9] = new prodobj('Tent Chairs Hire',1000.00);
prodlist[10] = new prodobj('Grave Arrangement',550.00);
ordData = new MakeArray(RowsInForm);
for (var i=1; i<= RowsInForm; i++) {
ordData = new ordobj(0,0,0,0);
}
</script>
</p>
<form name="ordform" method="post" action="someHandler">
<table align="center" border="1"><tr>
<th width="192" <b>Product</b></th>
<th width="72" align="center"><b>Qty</b></th>
<th width="120" align="center"><b>Unit Price</b></th>
<th width="120" align="center"><b>Ext Price</b></th>
</tr>
<script type="text/JavaScript">
for (var rownum=1;rownum<=RowsInForm;rownum++) {
document.write('<tr><td width=192 >');
document.write('<select name="prodchosen'+rownum+'" onChange="updateRow('+rownum+')">');
for (i=0; i<=ProductsInList; i++) {
document.write ("<option>"+prodlist.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 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>');
}
</script>