Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    order entry questions

    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:

    http://spectrum-enterprise.com/sm/smorder.html

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,698
    Thanks
    93
    Thanked 4,947 Times in 4,908 Posts
    That page just doesn't make any sense at all.

    There is no logical way to tie each item in a single row together:
    Code:
    <input NAME=price_sku74159 VALUE='' >
    <input NAME=price_desc74160 VALUE='' >
    <input NAME=price_item74161 VALUE='' >
    <SELECT NAME=qty_item74162 >
         ...
    </SELECT>
    <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.:
    Code:
    <input NAME=sku_1 VALUE='' >
    <input NAME=desc_1 VALUE='' >
    <input NAME=item_1 VALUE='' >
    <SELECT NAME=qty_1 >
         ...
    </SELECT>
    <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.

  3. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,698
    Thanks
    93
    Thanked 4,947 Times in 4,908 Posts
    Here...possibly a waste of my time, but I'll try to convince you, anyway.

    Try this HTML page:
    Code:
    <html>
    <head>
    <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 {
            ReCalc();
        }
    }
    </script>
    </head>
    <body>
    <form>
    <table>
        <tr>
            <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>
        </tr>
        <tr>
            <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>
        </tr>
        <tr>
            <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>
        </tr>
        <tr>
            <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>
        </tr>
        <tr>
            <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>
        </tr>
        <tr>
            <td colspan="3"></td>
            <td>Subtotal:</td>
            <td><input name="subtotal" readonly size="7"></td>
        </tr>
        <tr>
            <td colspan="3"></td>
            <td>Shipping:</td>
            <td><input name="shipping" readonly size="7"></td>
        </tr>
        <tr>
            <td></td>
            <td>Tax Rate:</td>
            <td><input name="taxrate" size="5" onchange="numonly(this);">%</td>
            <td>Tax:</td>
            <td><input name="tax" readonly size="7"></td>
        </tr>
        <tr>
            <td colspan="3"></td>
            <td>Total:</td>
            <td><input name="total" readonly size="7"></td>
        </tr>
    </table>
    </form>
    </body>
    </html>

  4. #4
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  5. #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,698
    Thanks
    93
    Thanked 4,947 Times in 4,908 Posts
    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!!


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •