www.webdeveloper.com
Results 1 to 9 of 9

Thread: Calculating the total with jscript

  1. #1
    Join Date
    May 2007
    Posts
    14

    Calculating the total with jscript

    I cannot for the life of me figure out why my subtotal isn't working right with my form. It coinsides with Salesforce and Click and Pledge variables but not sure why it doesn't work now...UGH!!!

    https://www.jhalliance.org/35thAnniv...HAlliance2.htm

    Any assistance would be GREATLY appreciated. Thank you in advance. Nezz


  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,517
    Please post code you are having problems with in [CODE]...[/CODE] tags and if you are using JQuery, please post your problem in the JavaScript Frameworks forum.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    May 2007
    Posts
    14
    Code:
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    
    function calcsubtotal(){
    var a = Number($('UnitPrice1').val()),
    b = $('Quantity1').val().split(','),
    price = b[1].split(":");
    $('subtotal').html('<b>$' + a * Number(price[1]) + '.00</b>');
    }
    
    $('Quantity1,UnitPrice1').change(calcsubtotal);
    calcsubtotal();
    });
    </script>
    <INPUT TYPE="Checkbox" name="UnitPrice1" id="UnitPrice1" value="Ticket, Option 1 Name:175:0:1:1234567890">
    <span class="questions">I would like to buy tickets to the 35th Anniversary Party at 
     <input name="UnitPrice1" type="text" id="UnitPrice1" value="175" size="7" />
    per ticket </span>
    <input name="ItemID1" type="hidden" id="ItemID1" value="1" />
                  <input name="ItemName1" type="hidden" id="ItemName1" value="Ticket" />
                  <input name="UnitDeductible1" type="hidden" id="UnitDeductible1" value="100%" />
    
    </td></tr>
    <tr><td>
    <p class="subs">Choose A Quantity 
      <input name="Quantity1" id="Quantity1" type="text" value="1" size="6">
    </p></td></tr>
    <tr><td valign="top">
    <p class="questions" style="float:left; font-size:16px;"><b>Sub-Total:</b></p> <p class="questions" id="subtotal" style="float:right; font-size:16px;"><b>$175.00</b></p> </td></tr>

  4. #4
    Join Date
    Oct 2013
    Posts
    610
    Code:
    <INPUT TYPE="Checkbox" name="UnitPrice1"  id="UnitPrice1" value="Ticket, Option 1 Name:175:0:1:1234567890">
    Code:
    <input name="UnitPrice1" type="text" id="UnitPrice1" value="175" size="7" />
    See anything wrong there?? You cannot have more than one element with the same ID. It's the rules. For that matter, having 2 elements with name="UnitPrice1" might wreak havoc with your form handling script.
    Last edited by Kevin2; 07-24-2014 at 03:26 PM.

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,517
    Note: <script src="http://code.jquery.com/jquery-latest.min.js"></script>

    So your query should have been posted in the JavaScript Frameworks forum
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  6. #6
    Join Date
    Oct 2013
    Posts
    610
    And BTW, Google Chrome's console shows this:
    [blocked] The page at 'https://www.jhalliance.org/35thAnnivTicket_JHAlliance2.htm' was loaded over HTTPS, but ran insecure content from 'http://code.jquery.com/jquery-latest.min.js': this content should also be loaded over HTTPS.
    Which means the JQuery library MAY NOT GET LOADED! Which means your subtotal may not get calculated!

  7. #7
    Join Date
    May 2007
    Posts
    14
    Okay...thank you! I will look into it. I appreciate the assistance. Its a headache because most of the content references something from SalesForce but those guys aren't javascript savvy so Im stuck in the middle.

  8. #8
    Join Date
    Oct 2013
    Posts
    610
    Who is "SalesForce"? The Merchant Account place? If they don't know JavaScript it may be time to look for another CC processor.

    Actually, you're using JQuery -- not "pure" JavaScript. And I can create a script to do that math and drop it into the page in about 3 lines of "pure" JavaScript; no JQuery necessary. The problem may be how your form handling script interacts with that.

    Ancillary to that is the fact that your potential users can change the "cost/item" field from $175 to whatever they want. Scary? How would you like 100 people buying what should be $175 tickets for $1.75 each? Cuts into the night's gross (and net) doesn't it? Might be possible with your current code. If it were me I'd change
    Code:
    <input name="UnitPrice1" type="text" id="UnitPrice1" value="175" size="7" />
    to:
    Code:
    <input name="UnitPrice1" type="hidden" id="UnitPrice1" value="175" />
    Then change
    HTML Code:
    <span class="questions">I would like to buy tickets to the 35th Anniversary Party at 
     <input name="UnitPrice1" type="text" id="UnitPrice1" value="175" size="7" />
    per ticket </span>
    to:
    HTML Code:
    <span class="questions">I would like to buy tickets to the 35th Anniversary Party at $175.00 per ticket </span>
    Just sayin'...

  9. #9
    Join Date
    May 2007
    Posts
    14
    Thank you a ton for the help. I found the original sample that I used in the beginning online that seems to work okay. Im still working out the look of it but seems to be processing correctly.

    Salesforce is a cc processor that my client uses. I don't have a say in the matter but I think things are finally starting to go right. I really really appreciate you taking the time to answer my questions! I guarantee that I will have more questions but I wanted to send a thank you first!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles