View Full Version : order entry questions

Oct 20th, 2009, 05:24 PM
I have a script that needs extra variables added, but need some help on how to do it. I need a textbox to add shipping charges, and also a text box to add sales tax. Then these 2 amounts need to be added to the grand total. Any help appreciated.

The link below is to the page that has the form and code:


Old Pedant
Oct 20th, 2009, 11:01 PM
That page just doesn't make any sense at all.

There is no logical way to tie each item in a single row together:

<input NAME=price_sku74159 VALUE='' >
<input NAME=price_desc74160 VALUE='' >
<input NAME=price_item74161 VALUE='' >
<SELECT NAME=qty_item74162 >
<INPUT NAME=total_item74163>

Okay, now that I simplified it down to this, I see what you are doing. But *WHY*???

Why increment the number for each field??? The text portion of the field should be enough.

Why not K.I.S.S.:

<input NAME=sku_1 VALUE='' >
<input NAME=desc_1 VALUE='' >
<input NAME=item_1 VALUE='' >
<SELECT NAME=qty_1 >
<INPUT NAME=total_1>


Would make all the JS code *TONS* simpler.

You could probably strip all that JS code down to maybe a dozen or so lines if you didn't use all the funky field names.

I dunno about anybody else, but quite frankly I don't want to think about trying to tackle adding stuff to this mess, as it now sits.

Old Pedant
Oct 20th, 2009, 11:47 PM
Here...possibly a waste of my time, but I'll try to convince you, anyway.

Try this HTML page:

<script type="text/javascript">
function ReCalc( )
var form = document.forms[0];
var subtotal = 0;
for ( var row = 1; row <= 5; ++row )
var price = parseFloat( form.elements["price_"+row].value );
if ( isNaN(price) ) price = 0;
var qty = form.elements["qty_"+row].selectedIndex + 1;
var itemtotal = price * qty;
subtotal += itemtotal;
form.elements["total_"+row].value = "$" + itemtotal.toFixed(2);
form.subtotal.value = "$" + subtotal.toFixed(2);

var shipping = subtotal * 0.10;
shipping = Math.round( shipping * 100 ) / 100; // round to the penny
form.shipping.value = "$" + shipping.toFixed(2);

var taxrate = parseFloat( form.taxrate.value );
if ( isNaN( taxrate ) ) taxrate = 0;
// if tax is based on subtotal plus shipping, add shipping to subtotal here
var tax = subtotal * taxrate / 100;
tax = Math.round( tax * 100 ) / 100; // round to the penny
form.tax.value = "$" + tax.toFixed(2);

total = subtotal + shipping + tax;
form.total.value = "$" + total.toFixed(2);

var reNum = /[^\d\.]/g;
function numonly(fld)
var num = fld.value.replace( reNum, "" );
fld.value = num;
num = parseFloat(num);
if ( isNaN(num) )
alert("That value is not a legal number!");
fld.value = "0";
} else {
<td><input name="sku_1" size="10"></td>
<td><input name="desc_1" size="25"></td>
<td><input name="price_1" size="5" onchange="numonly(this);"></td>
<td><select name="qty_1" onchange="ReCalc()"><option>1<option>2<option>3<option>4<option>5</select></td>
<td><input name="total_1" readonly size="7"></td>
<td><input name="sku_2" size="10"></td>
<td><input name="desc_2" size="25"></td>
<td><input name="price_2" size="5" onchange="numonly(this);"></td>
<td><select name="qty_2" onchange="ReCalc()"><option>1<option>2<option>3<option>4<option>5</select></td>
<td><input name="total_2" readonly size="7"></td>
<td><input name="sku_3" size="10"></td>
<td><input name="desc_3" size="25"></td>
<td><input name="price_3" size="5" onchange="numonly(this);"></td>
<td><select name="qty_3" onchange="ReCalc()"><option>1<option>2<option>3<option>4<option>5</select></td>
<td><input name="total_3" readonly size="7"></td>
<td><input name="sku_4" size="10"></td>
<td><input name="desc_4" size="25"></td>
<td><input name="price_4" size="5" onchange="numonly(this);"></td>
<td><select name="qty_4" onchange="ReCalc()"><option>1<option>2<option>3<option>4<option>5</select></td>
<td><input name="total_4" readonly size="7"></td>
<td><input name="sku_5" size="10"></td>
<td><input name="desc_5" size="25"></td>
<td><input name="price_5" size="5" onchange="numonly(this);"></td>
<td><select name="qty_5" onchange="ReCalc()"><option>1<option>2<option>3<option>4<option>5</select></td>
<td><input name="total_5" readonly size="7"></td>
<td colspan="3"></td>
<td><input name="subtotal" readonly size="7"></td>
<td colspan="3"></td>
<td><input name="shipping" readonly size="7"></td>
<td>Tax Rate:</td>
<td><input name="taxrate" size="5" onchange="numonly(this);">%</td>
<td><input name="tax" readonly size="7"></td>
<td colspan="3"></td>
<td><input name="total" readonly size="7"></td>

Oct 21st, 2009, 02:46 AM
I did not code this page originally.

It was found by my partner while looking for an order entry script.

Thank you for the input and code.
With your help I think we will be able to add the features we need.

Old Pedant
Oct 21st, 2009, 03:38 AM
Oh, good. I'm glad I didn't step on your personal toes. Honest, that was a horribly designed page. Mine is surely not perfect, but at least it gives you a hope of modifying it as neede, I think.

Best of luck!

Feel free to ask more questions!!