Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:26:01+00:00 2026-06-11T15:26:01+00:00

Okay so basically I’ve got a form where you enter items you want to

  • 0

Okay so basically I’ve got a form where you enter items you want to purchase and at any point during that you can select a standard and show discount and those discounts apply to the items you’ve added in real time, now the discount both work fine with they were regular text fields, but switching them to drop downs to limit the values that can be entered has broken my code, curious if anyone can help me out… the two form elements have IDs of st_disc and sh_disc…

Here is HTML from the form, ignore all the extra php, that is though so if the form is incorrectly submitted it remembers the choice that was selected…

    <td colspan="2" style="border-width:0px; padding:10px; text-indent: 10px;"><p class="tdblackbigger">Standard Discount:</p></td>
    <td style="border-width:0px; padding:10px; text-indent: -105px;"><p class="tdblackbigger">
        <?php $restdisc = $_REQUEST['st_discount']; ?>
        <?php $attr7 = 'selected="selected"'; ?>
        <select name="st_discount" id="st_disc" class="invoiceselect">
            <option selected="selected" value="">------</option>
            <option value="20"<?php echo $restdisc == '20' ? $attr7 : ''; ?>>20</option>
            <option value="35"<?php echo $restdisc == '35' ? $attr7 : ''; ?>>35</option>
            <option value="40"<?php echo $restdisc == '40' ? $attr7 : ''; ?>>40</option>
            <option value="45"<?php echo $restdisc == '45' ? $attr7 : ''; ?>>45</option>
        </select>
    </td>
    <td colspan="2" style="border-width:0px; padding:10px;"><p class="tdblackbigger">Show Discount:</p></td>
    <td style="border-width:0px; padding:10px; text-indent: -135px;"><p class="tdblackbigger">
        <?php $reshdisc = $_REQUEST['sh_discount']; ?>
        <?php $attr8 = 'selected="selected"'; ?>
        <select name="sh_discount" id="sh_disc" class="invoiceselect">
            <option selected="selected" value="">------</option>
            <option value="5"<?php echo $reshdisc == '5' ? $attr8 : ''; ?>>5</option>
            <option value="10"<?php echo $reshdisc == '10' ? $attr8 : ''; ?>>10</option>
            <option value="15"<?php echo $reshdisc == '15' ? $attr8 : ''; ?>>15</option>
            <option value="20"<?php echo $reshdisc == '20' ? $attr8 : ''; ?>>20</option>
            <option value="25"<?php echo $reshdisc == '25' ? $attr8 : ''; ?>>25</option>
        </select>
    </td>

And here is the JS written that was working when they were text boxes, I’m better at PHP than JS so it’s probably something simple..

$(document).ready(function() {   
    $("input").keyup(function() {
    var subtotal = 0;
    var stantot = 0;
    var showtot = 0;
        for (var i = 0; i <= 30; i++) {
        var unitp = parseFloat($("#unitp" + i).val()) || 0;
        var casep = parseFloat($("#casep" + i).val()) || 0;
        var units = parseFloat($("#units" + i).val()) || 0;
        var cases = parseFloat($("#cases" + i).val()) || 0;
        var st_disc = parseFloat($("#st_disc").val()) || 0;
        var sh_disc = parseFloat($("#sh_disc").val()) || 0;

        var unitr = (unitp * units);
        var caser = (casep * cases);
        var result = (unitr + caser);
        var st_disc_fix = (st_disc / 100);
        var sh_disc_fix = (sh_disc / 100);
        var st_disc_solo = (st_disc_fix * result);
        var sh_disc_solo = (sh_disc_fix * result);
        var st_disc_amt = (result - st_disc_solo);
        var sh_disc_amt = (st_disc_amt - sh_disc_solo);
        var disc_total = (st_disc_fix + sh_disc_fix);
        var disc_whole = (disc_total * result);

        var disc = (result - disc_whole);
        var st_disc_tot = (result - disc_whole);
        var sh_disc_tot = (result - disc_whole);

        $("#line" + i).val(result.toFixed(2));
        $("#disc" + i).val(disc.toFixed(2));
        subtotal += parseFloat(result);
        stantot += parseFloat(st_disc_amt);
        showtot += parseFloat(sh_disc_amt);
    }
    $("#totretail").val(subtotal.toFixed(2));
    $("#standiscount").val(stantot.toFixed(2));
    $("#showdiscount").val(showtot.toFixed(2));

    var totship = ($("#totship").val() * 1);

    var finaltotal = (showtot + totship);
    $("#total").val(finaltotal.toFixed(2));

    });
 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:26:02+00:00Added an answer on June 11, 2026 at 3:26 pm

    Looks like you are missing the main point here..

    var st_disc = parseFloat($("#st_disc").val());
    var sh_disc = parseFloat($("#sh_disc").val());
    
    $("#st_disc").val()   and  $("#sh_disc").val()  is messing your logic here
    

    “#st_disc” is the id of the selected element and it does not have a value .. The options inside will have a selected value..

    So var st_disc = parseFloat($("#st_disc").val()); should be

         var st_disc = parseFloat($("#st_disc  option:selected").val()) || 0;
    
    var sh_disc = parseFloat($("#sh_disc option:selected").val()) || 0;
    
    
                                OR
    
    var st_disc = parseFloat($("#st_disc").find(":selected").val()) || 0;
    
    var sh_disc = parseFloat($("#sh_disc").find(":selected").val()) || 0;​ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so basically I coded this app that does some calculations for each point
Okay, next PHPExcel question. I have an HTML form that users fill out and
 Okay, so emoji basically shows the above on a computer. Is that another
Okay, Ive got a cog (toothed gear) that I have drawn in opengl. I
Okay I've got a problem I'd appreciate someone spreading some light on. Basically I
Okay basically I am creating a stored procedure that will return data for our
Okay, got a question. I have assembled a bit mask for options. Basically my
Okay, this is an easy one, but I can't figure it out. Basically I
Okay, so this seems simple, but I can't think of a straightforward solution; Basically
Okay so basically I am creating a Workflow BPMS in SharePoint and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.