Undefined function error for javascript function - Stack Overflow

Here is my code, I don't understand what's wrong.<script type="textjquery">f

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?

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?

Share Improve this question edited Oct 23, 2011 at 0:50 hammar 140k18 gold badges309 silver badges388 bronze badges asked Oct 23, 2011 at 0:11 Michael DavisMichael Davis 2675 silver badges18 bronze badges 7
  • This may be a sneaky error - see stackoverflow./questions/153909/… – Caffeinated Commented Oct 23, 2011 at 0:14
  • @Adel - Your link is a circular reference. – Jared Farrish Commented Oct 23, 2011 at 0:14
  • I'm not seeing anything specific wrong with what you posted: jsfiddle/LZVp6 – Jared Farrish 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? – Keith.Abramo Commented Oct 23, 2011 at 0:18
  • $this->gettotalAdult() I don't think you can use -> syntax in JS, can you? – vol7ron Commented Oct 23, 2011 at 0:21
 |  Show 2 more ments

1 Answer 1

Reset to default 6

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744218980a4563689.html

相关推荐

  • Undefined function error for javascript function - Stack Overflow

    Here is my code, I don't understand what's wrong.<script type="textjquery">f

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信