Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Currency value in javascript

NealNeal South AfricaMember Posts: 1

Hi Guys, Hope you can help me with this, I'm new to JavaScript.
The code below works perfectly - It takes the value of 1st drop down selected and adds it to the 2nd Drop down selected which gives a total.
The total given is only in numbers e.g 5539
I would like to add a currency value in front of the total such as $5539.00 or in my case (ZAR) R5539.00

How do I change the code to allow me to do this?
Thanks.

script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <select id="copy" name="copies" style="width: 100%; height: 50px">
              <option>Select Number of Copies</option>
              <option value="358.00">1 Copy</option>
              <option value="716.00">2 Copies</option>
              <option value="1074.00">3 Copies</option>
              <option value="1432.00">4 Copies</option>
              <option value="1790.00">5 Copies</option>
              <option value="2148.00">6 Copies</option>
    </select>

    <select id="addSlide" name="slides" style="width: 100%; height: 50px">
      <option value="0"> No</option>
      <option value="716.00"> Yes</option>
    </select>


    $(document).ready(function() {
      $('select').on('change', function() {
        $('#totalprice')[0].innerHTML = parseInt($('#copy option:selected').val(), 10) +
          parseInt($('#addSlide option:selected').val(), 10)    
      });

Best Answer

  • B00B00 Member Posts: 97 ✭✭✭
    Accepted Answer

    Try $('#totalprice')[0].innerHTML = 'R' + (parseInt($('#copy option:selected').val(), 10) + parseInt($('#addSlide option:selected').val(), 10))

Sign In or Register to comment.