0

I'm using this guide to add a calculation in a form that takes a price, multiplies it by a quantity (set by dropdown) and outputs to a total.

My final code is this:

function totalQuantity(){
  getPrice_6();
  //calculate a grand total based on the available product field
  quantity = parseInt(document.getElementById('quantity').value);
  //retrieve the value selected in the "quantity" field
  currentTotal = parseFloat(document.getElementById('total').value);
  //adjust displayed total
  total = quantity * currentTotal;
  //re-calculate the total based on the value selected in the "quantity" field
  document.getElementById('total').value = total.toFixed(2);
  //convert the "total" field's value to a float number followed by 2 decimals
  document.getElementById('payment_total_6').innerHTML = total.toFixed(2) + ' AUD';
  //display the total field's value along with the "USD" currency code
  document.getElementsByName('form[rsfp_Total]')[0].value = total.toFixed(2);
 
return true;
}
 
    window.addEvent('domready', function() {
 
totalQuantity();
    });

However on changing the quantity field I get a console error: Uncaught ReferenceError: getPrice_6 is not defined.

As per the guide, '6' is the ID of the form I'm using.

It seems like I've missed something obvious, but I can't figure out what.

  • where is the function `getPrice_6` created – Arun P Johny Mar 09 '15 at 03:07
  • And what is `getPrice_6();` supposed to actually do? (Given that without that line the rest of the function does seem like it would do what you want, except that you call it once when the DOM is ready, before the user has had a chance to enter any values...) – nnnnnn Mar 09 '15 at 03:15
  • When the line getPrice_6(); is executed, the program is looking for a function called getPrice_6() and can't find it, hence the error message. Where's the piece of code that says function getPrice_6() { .... } ? – frenchie Mar 09 '15 at 03:15
  • Thanks everyone - there doesn't appear to **be** another function called getPrice_6 - as per the documentation I was following, that's the entire javascript provided apart from the snippets on the quantity and total fields that update the total. – Kelsey Brookes Mar 09 '15 at 07:38

0 Answers0