PDA

View Full Version : Remove third column from table



Jay Dog
02-12-2013, 08:45 AM
Hi,

I've been working on this bit of code I found based on an Order Form that I intend to modify to help children understand the different costs of materials.

This one is for flap jacks:


The third column with UNIT PRICE serves no real purpose and therefore should be removed. I have tried to delete it but unfortunately it causes the code to not run correctly. Any help would be greatly appreciated.

Thanks.


Jay Dog


http://www.bigwood.nottingham.sch.uk/uploads/vle/flapjack.html

Jay Dog
02-12-2013, 08:47 AM
<HTML>
<HEAD>
<TITLE>Order Form</TITLE>
<SCRIPT>

//Global Variables

var RowsInForm = 6 //How many rows will be in the order details form

var ProductsInList = 18 //Must equal highest subscript in product list

var SalesTaxRate = 0.0775 //Set to sales tax rate in decimal. e.g. 0.0775 is 7.75%

var TaxableState = "UK" //Set to name of state you charge sales tax in

var ProdSubscript = 0 //Identifies subscript of selected product in current row.


// Function to create a new empty array that starts at 1.

function MakeArray(n) {

this.length = n

for (var i = 1; i<= n; i++) {

this[i] = 0

}

return this

}


// Function to create a new, empty array that starts at zero.

function BuildZeroArray(n) {

this.length = n

for (var i = 0; i<= n; i++) {

this[i] = 0

}

return this

}


// Define a custom object named prodobj (Product Object).

// An array of these objects will act as our product/price list.

function prodobj(name, unitprice) {

this.name = name

this.unitprice = unitprice

}


// Define a new custom object named ordobj (Order Object).

// Will house real numbers from order form to help with math.

function ordobj(prodsub, qty, unitprice, extprice) {

this.prodsub = prodsub

this.qty = qty

this.unitprice = unitprice

this.extprice = extprice

}


//convert any non-numeric value to a zero.

function strToZero(anyval) {

anyval = ""+anyval

if (anyval.substring(0,1) < "0" || anyval.substring(0,1) > "9") {

anyval = "0"

}

return eval(anyval)

}


//update current row in order array and form.

function updateRow(rownum){

var exec = 'ProdSubscript = document.ordform.prodchosen'+rownum+'.selectedIndex'

eval (exec)

ordData[rownum].prodsub=ProdSubscript //get qty from the form

var exec='tempqty=document.ordform.qty'+rownum+'.value'

eval (exec)

ordData[rownum].qty = strToZero(tempqty) //get unit price from the product price list.

ordData[rownum].unitprice=prodlist[ProdSubscript].unitprice

ordData[rownum].extprice = (ordData[rownum].qty) * ordData[rownum].unitprice

var exec = 'document.ordform.unitprice'+rownum+'.value = currencyPad(ordData['+rownum+'].unitprice,10)'

eval (exec)

var exec = 'document.ordform.extprice'+rownum+'.value = currencyPad(ordData['+rownum+'].extprice,10)'

eval (exec)

updateTotals() //update totals at bottom of form

}


//update the totals in the lower part of order details.

function updateTotals() {

var subtotal = 0

for (var i=1; i<=RowsInForm; i++) {

subtotal = subtotal + ordData[i].extprice

}

document.ordform.subtotal.value = currencyPad(subtotal,10)

salestax = 0

if (document.ordform.Taxable.checked) {

salestax = SalesTaxRate * subtotal

}

document.ordform.salestax.value = currencyPad(salestax,10)

document.ordform.grandtotal.value = currencyPad(subtotal+salestax,10)

}


//copy the "Bill To" information to the "Ship To" information.

function copyAddress() {

document.ordform.ShipName.value = document.ordform.billName.value

document.ordform.ShipCompany.value = document.ordform.billCompany.value

document.ordform.ShipAdd1.value = document.ordform.billAdd1.value

document.ordform.ShipAdd2.value = document.ordform.billAdd2.value

document.ordform.ShipCSZ.value = document.ordform.billCSZ.value

}


function currencyPad(anynum,width) {

//returns number as string in £xxx,xxx.xx format.

anynum = "" + eval(anynum)

//evaluate (in case an expression sent)

intnum = parseInt(anynum)

//isolate integer portion

intstr = ""+intnum

//add comma in thousands place.

if (intnum >= 1000) {

intlen = intstr.length

temp1=parseInt(""+(intnum/1000))

temp2=intstr.substring(intlen-3,intlen)

intstr = temp1+","+temp2

}

if (intnum >= 1000000) {

intlen = intstr.length

temp1=parseInt(""+(intnum/1000000))

temp2=intstr.substring(intlen-7,intlen)

intstr = temp1+","+temp2

}

decnum = Math.abs(parseFloat(anynum)-parseInt(anynum)) //isolate decimal portion

decnum = decnum * 100 // multiply decimal portion by 100.

decstr = "" + Math.abs(Math.round(decnum))

while (decstr.length < 2) {

decstr += "0"

}

retval = intstr + "." + decstr

if (intnum < 0) {

retval=retval.substring(1,retval.length)

retval="("+retval+")"

}

retval = "£"+retval

while (retval.length < width){

retval=" "+retval

}

return retval

}

</SCRIPT>

Jay Dog
02-12-2013, 08:48 AM
</HEAD>
<BODY aLink=#8a8a8a bgColor=#ffffff
link=#ff0000 text=#000000 vLink=#215e21>
<H3 align=center><FONT size=+1>'Flap Jack Costing Sheet</FONT></H3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle">&nbsp;</td>
<td align="left" valign="middle">My name is:</td>
<td align="right" valign="middle">&nbsp;</td>
<td align="left" valign="middle">My teacher is:</td>
<td align="right" valign="middle">&nbsp;</td>
<td align="left" valign="middle">My class is:</td>
<td align="left" valign="middle">&nbsp;</td>
<td align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td width="3%" align="center" valign="middle">&nbsp;</td>
<td width="26%" align="left" valign="middle"><input name="name" type="text" id="name" style="width:220px;" /></td>
<td width="9%" align="right" valign="middle">&nbsp;</td>
<td width="18%" align="left" valign="middle"><select name="teacher" id="teacher">
<option value=""></option>
<option value="Mr Booth">Mr Booth</option>
<option value="Mr Gilkerson">Mr Gilkerson</option>
<option value="Mr Hayes">Mr Hayes</option>
<option value="Ms Kandola">Ms Kandola</option>
<option value="Mrs Perry">Mrs Perry</option>


</select></td>
<td width="10%" align="right" valign="middle">&nbsp;</td>
<td width="10%" align="left" valign="middle"><select name="class" id="class">
<option value=""></option>
<option value="7A1">7A1</option>
<option value="7A2">7A2</option>
<option value="7A3">7A3</option>
<option value="7A4">7A4</option>
<option value="7B1">7B1</option>
<option value="7B2">7B2</option>
<option value="7B3">7B3</option>
<option value="7B4">7B4</option>
</select></td>
<td width="13%" align="left" valign="middle">&nbsp;</td>
<td width="11%" align="left" valign="middle"></form>
<input type="button"
onClick="window.print()"
value="Print This Page"/></td>
</table>
<SCRIPT>

//Create a new array named prodlist with six elements.

prodlist = new BuildZeroArray(ProductsInList) //Refers to global variable ProductsInList

//Populate that array with this product info.

//The first item, prodlist[0] must be a "non-product" with

//a unitprice of zero.

prodlist[0] = new prodobj('-none-',0)

prodlist[1] = new prodobj('Oats',0.0012)

prodlist[2] = new prodobj('Sugar',0.00099)

prodlist[3] = new prodobj('Margarine',0.002)

prodlist[4] = new prodobj('Golden Syrup',0.00024)

prodlist[5] = new prodobj('Butter x',0.00024)

prodlist[6] = new prodobj('Raisins',0.00308)

prodlist[7] = new prodobj('Sultanas',0.00308)

prodlist[8] = new prodobj('Banana',0.00079)

prodlist[9] = new prodobj('Apple',0.00195)

prodlist[10] = new prodobj('Pears',250.00)

prodlist[11] = new prodobj('Dried Apricots',0.00499)

prodlist[12] = new prodobj('Cherries',0.0109)

prodlist[13] = new prodobj('Dates x',250.00)

prodlist[14] = new prodobj('Walnuts x',14.99)

prodlist[15] = new prodobj('Coconut x',250.00)

prodlist[16] = new prodobj('Marshmallows x',250.00)

prodlist[17] = new prodobj('Chocolate Chips x',250.00)

prodlist[18] = new prodobj('Honey',250.00)

prodlist[19] = new prodobj('Strawberries',250.00)

prodlist[20] = new prodobj('Peanut Butter',250.00)



//Create a new array, named ordData, that contains empty Order Objects.

ordData = new MakeArray(RowsInForm)

for (var i=1; i<= RowsInForm; i++) {

ordData[i] = new ordobj(0,0,0,0)}

</SCRIPT>
<! A real form would require METHOD = and ACTION= attributes in the FORM tag below ><! to ensure that the data gets sent somewhere. The contents of the tag would be something ><! like FORM name="ordform" METHOD="POST" ACTION="youremailaddress" where youremailaddress ><! really is your e-mail address. However, even that would work only if your ISP supports ><! the use of mailto: in a form tag. If in doubt, contact your ISP for specifics. >
<FORM name=ordform></P>
<CENTER>
<P><! Display the table header></P>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30%"><img src="https://jupiter.inthehive.net/sites/bigwood/Departments/3083/Costing/flapjack.jpg" width="290" height="290"></td>
<td width="70%" align="center" valign="top"><table align=center border=1>
<center>
<tbody>
<tr>
<th width=192> <center>
<b>Product</b>
</center></th>
<th width=120> <center>
<b>Weight (g)</b>
</center></th>
<th width=120> <center>
<b>Unit Price</b>
</center></th>
<th width=120> <center>
<b>Ext Price</b>
</center></th>
</tr>
<! Generate the rest of the rows using JavaScript>
<br>
<script>

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[i].name)

} document.write ('</SELECT>')

document.write ('</TD><TD WIDTH=72><CENTER><INPUT NAME="qty'+rownum+'" VALUE=""')

document.write ('MAXLENGTH="3" SIZE=3 onChange="updateRow('+rownum+')"></CENTER>')

document.write ('</TD><TD WIDTH=120><CENTER>')

document.write ('<INPUT NAME="unitprice'+rownum+'" VALUE="" MAXLENGTH="10"')

document.write ('SIZE=10 onfocus="this.blur()"></CENTER>')

document.write ('</TD><TD WIDTH=120><CENTER>')

document.write ('<INPUT NAME="extprice'+rownum+'" VALUE="" MAXLENGTH="10"')

document.write ('SIZE=10 onfocus = "this.blur()"></CENTER>')

document.write ('</TD></TR>')

}

</script>
<p></p>
</center>
</table>
<center>
<p>
<! Second table holds subtotal, sales tax, grand total>
</p>
</center>
<table align="center">
<tbody>
<tr>
<td width=264></td>
<td width=120><center>
<p>Subtotal: </p>
</center></td>
<td width=120><center>
<p>
<input maxlength=10 name=subtotal onFocus=this.blur()
size=10>
</p>
</center></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>
<! In real life, you'd want to omit the whole onclick... thing in the input tag below. >
<! Which is to say you want to get rid of... >
<! onClick = "alert('I do not really get submitted anywhere. But thanks for trying me!')" ><! In real life, you can omit the entire input tag (i.e. the entire line) below >

</td>
</tr>
</table>
</CENTER>


</FORM></P>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle"><strong>
<label for="Comments">Comments</label>
</strong></td>
</tr>
<tr>
<td align="center" valign="middle"><textarea name="Comments" id="Comments" cols="100" rows="5"></textarea></td>
</tr>
</table>

</body>
</html>