3

Here is my code, I don't understand what's wrong.

    <script type="text/jquery">

function gettotalAdult()
{
    //Assume form with id="fsd-bucket-calc"
    var theForm = document.forms["fsd-bucket-calc"];
    //Get a reference to the # of Adults & 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;
}

</script>

This is my HTML:

<input type="text" name="totalAdult" id="totalAdult" onkeyup="gettotalCalories()" />

This is my error:

gettotalCalories is not defined

If it helps, the script is in the head of a WordPress page. Does anyone see what I'm doing wrong?

7
  • This may be a sneaky error - see stackoverflow.com/questions/153909/… Commented Oct 23, 2011 at 0:14
  • @Adel - Your link is a circular reference. Commented Oct 23, 2011 at 0:14
  • I'm not seeing anything specific wrong with what you posted: jsfiddle.net/LZVp6 Commented Oct 23, 2011 at 0:16
  • Are you sure your script is loading into the page. Have you fired up firebug or chrome's console to see what scripts are loaded? Commented Oct 23, 2011 at 0:18
  • $this->gettotalAdult() I don't think you can use -> syntax in JS, can you? Commented Oct 23, 2011 at 0:21

1 Answer 1

6

You have <script type="text/jquery"> you may need <script type="text/javascript"> instead.

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

5 Comments

lol... I think that was it! Now I'm getting a different error: Cannot set property 'innerHTML' of null, but at least I can start tracing that down now that something is working!
Just saw this, you beat me to it.
When I first noticed that, I didn't think that was so important.
@MichaelDavis you shouldn't change the question... it makes the answer more confusing
@vol7ron - Good point! I'll edit that... I appreciate all the help! I'm always amazed how responsive everyone is here.

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.