Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined function error for javascript function
    text
    copied!<p>Here is my code, I don't understand what's wrong.</p> <pre><code> &lt;script type="text/jquery"&gt; function gettotalAdult() { //Assume form with id="fsd-bucket-calc" var theForm = document.forms["fsd-bucket-calc"]; //Get a reference to the # of Adults &amp; Children var quantity = theForm.elements["totalAdult"]; var caloriesAdult = theForm.elements["caloriesAdult"]; var adultcalTotal=0; //If the totalAdult is not blank if(totalAdult.value!="") { adultcalTotal = parseInt(totalAdult.value)*parseInt(caloriesAdult.value); } return adultcalTotal; } function gettotalChild() { //Assume form with id="fsd-bucket-calc" var theForm = document.forms["fsd-bucket-calc"]; //Get a reference to the # of Children var totalChild = theForm.elements["totalChild"]; var caloriesChild = theForm.elements["caloriesChild"]; var childcalTotal=0; //If the totalChild is not blank if(totalChild.value!="") { childcalTotal = parseInt(totalChild.value)*parseInt(caloriesChild.value); } return childcalTotal; } function gettotalCalories() { //Here we get the total calories by calling our function //Each function returns a number so by calling them we add the values they return together var totalCalories = gettotalAdult() + gettotalChild(); //display the result document.getElementById('total-req-cal').innerHTML = "The total required calories are "+totalCalories; } &lt;/script&gt; </code></pre> <p>This is my HTML:</p> <pre><code>&lt;input type="text" name="totalAdult" id="totalAdult" onkeyup="gettotalCalories()" /&gt; </code></pre> <p>This is my error:</p> <blockquote> <p>gettotalCalories is not defined</p> </blockquote> <p>If it helps, the script is in the head of a WordPress page. Does anyone see what I'm doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload