0

I'm not sure what I am doing wrong, but I am just trying to get a total price to display after you make a selection. I want to take the value of the selection and multiply it by 100 and then use the updatetotal function to display the total.

// Collect Data & Prices To Update Dynamic Prices
 var pricechecking=document.getElementById('howmanyaccts')value.trim();
 var pricepaypal=document.getElementById('howmanyacctspaypal')value.trim();

 var pricecheck = pricechecking * 100;
 var pricepay = pricepaypal * 100;

 function updateTotal() {

 var ThePrice = pricecheck + pricepay;

 $('#TotalPrice').text('$' + ThePrice + '.00');
 }

 $(function () { $('.DoPricing').click(updateTotal); });

MY HTML IS:

<form action="http://linktomyactionpage" method="post" >
 <p>How many accounts to pay by check?</p>
 <select name="howmanyaccts" id="howmanyaccts" class="DoPricing">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
 </select>

 <p>How many accounts to pay by paypal?</p>
 <select name="howmanyacctspaypal" id="howmanyacctspaypal" class="DoPricing">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
 </select>

 <p>Total: <span id="TotalPrice">$0.00</span></p>

 <input type="submit" name="submit" value="submit">
 </form>

What if I simplified the code? Brought the 00.00 to the text and no multiplication?

 // Collect Data & Prices To Update Dynamic Prices
 var pricechecking=document.getElementById('howmanyaccts').value.trim();
 var pricepaypal=document.getElementById('howmanyacctspaypal').value.trim();

 function updateTotal() {

     var ThePrice = pricechecking + pricepaypal;

     $('#TotalPrice').text('$' + ThePrice + '00.00');
 }

 $(function () { $('.DoPricing').click(updateTotal); });

HERE IS WHAT I GOT TO WORK:

 // Collect Data & Prices To Update Dynamic Prices
 var pricechecking=document.getElementById('howmanyaccts').value.trim();
 var pricepaypal=document.getElementById('howmanyacctspaypal').value.trim();

 function updateTotal() {
 var pricecheck = parseInt($('#howmanyaccts').val(), 10);
 var pricepay = parseInt($('#howmanyacctspaypal').val(), 10);

     var ThePrice = pricecheck + pricepay;

     $('#TotalPrice').text('$' + ThePrice + '00.00');
 }

 $(function () { $('.DoPricing').click(updateTotal); });
4
  • Error here .getElementById('howmanyacctspaypal')value Commented Jun 19, 2013 at 4:57
  • For starters, you're writing getElementById(...)value at two places where it should be getElementById(...).value. If you want more detailed help, consider giving more detail about what problem you're facing. Commented Jun 19, 2013 at 4:58
  • @David - I'm not getting a total Commented Jun 19, 2013 at 5:02
  • I changed the .value and now the first dropdown gives me a value of $200.00 no matter what I select. Commented Jun 19, 2013 at 5:04

2 Answers 2

1

I think you want to do something like this : http://jsfiddle.net/F3HbJ/

$(function () {
    $('.DoPricing').change(function () {
        var total = 0;
        $('.DoPricing').each(function () {
            total += parseInt($(this).val()) * 100;
        });
        $('#TotalPrice').html('$' + total);
    });
});

The event handler is .change() for a select. Then you loop through the parseInt values of each select that you multiply by 100.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah I just figured that out too! Thanks!
Your code works better! My code didn't work on my site. Thanks again!
0

Here is working DEMO

use like this :

$(document).ready(function () {
        var pricechecking = $($("#howmanyaccts")[0].selectedOptions).attr("value");
        var pricepaypal = $($("#howmanyacctspaypal")[0].selectedOptions).attr("value");

        function updateTotal() {
            var pricecheck = parseInt($('#howmanyaccts').val(), 10);
            var pricepay = parseInt($('#howmanyacctspaypal').val(), 10);

            var ThePrice = pricecheck + pricepay;

            $('#TotalPrice').text('$' + ThePrice + '00.00');
        }

        $('.DoPricing').change(updateTotal);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.