Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Function Not Defined Error (BUT IT IS DEFINED)

I have a JavaScript function which fires on blur. Strangely enough it worked fine the first time I ran it, and ever since then I've been getting an error that says JavaScript Function Not Defined - and it stops running. I have googled around similar problems but none of the advice has been able to resolve the issue. Asp.Net 3.5 Webforms, if it matters. I have included some extra functions and lines of code which may be unrelated to the problem. The issue I'm having regards updateFiscalGrid, the large function. The HTML which binds to the event is below the function.

<%@ Page MasterPageFile="~/MasterPages/NPRPage.Master"  CodeBehind="NPRFundingApplication.aspx.cs" Inherits="Tea.Hcf.Web.Secured.NPRFundingApplication" AutoEventWireup="true" Language="C#" EnableEventValidation="true" MaintainScrollPositionOnPostback="true" %>

<%@ Register TagPrefix="ew" Namespace="eWorld.UI" Assembly="eWorld.UI" %>
<%@ Register TagPrefix="hcf" Namespace="Tea.Hcf.Web" Assembly="Tea.Hcf.Web" %>
<%@ Register Src="../Controls/NpCdnSearch.ascx" TagName="NpCdnSearch" TagPrefix="np1" %>
<%@ Register Src="../Controls/NpStudentRoster.ascx" TagName="NpStudentRoster" TagPrefix="np2" %>

<script type="text/javascript" language="javascript">
    //<![CDATA[

    function showMaxWin(nUrl) {
        var h = 600;
        var w = 800;
        var features = 'resizable=1, width=' + w + ', height=' + h + ', top=0, left=0';
        NewWin = window.open(nUrl, 'NewWin', features);
    }

    function dateChangedCallback() {
        updateSubTotals();
    }

    function updateFiscalGrid(){
        var RelatedServicesCost = document.getElementById('<%= RPCB_SUPP_SVCS_SUBTOTAL3.ClientID %>').value;
        var ResidentialCare = document.getElementById('<%= RPCB_RES_SVCS_SUBTOTAL3.ClientID %>').value;
        var TotalCostforResPlacement = document.getElementById('<%= TotalResidentialPlacement.ClientID %>').value;
        var SetAside = document.getElementById('<%= rblSetAsideMet.ClientID %>').value;
        var LocalTaxSubtraction = document.getElementById('<%= LocalTaxShareSubtraction.ClientID %>').value;
        var IDEABRelatedServiceCost = document.getElementById('<%= RelatedServicesSetAside.ClientID %>').value;
        var IDEABDiscretionaryServicesCost = document.getElementById('<%= RelatedServicesDiscretionary.ClientID %>').value;
        var IDEABREsidentialCare = document.getElementById('<%= ResidentialCareSetAside.ClientID %>').value;
        var IDEABDiscResCare = document.getElementById('<%= ResidentialCareDiscretionary.ClientID %>').value;
        var StateFSP = document.getElementById('<%= TotalEducationServices2.ClientID %>').value;
        var Discretionary = document.getElementById('<%= DiscretionaryTotal.ClientID %>').value;
        var IDEABAward = document.getElementById('<%= IdeaBAward.ClientID %>').value;
        if(SetAside = '0'){
            Discretionary = LocalTaxSubtraction + IDEABRelatedServiceCost + IDEABDiscretionaryServicesCost + IDEABREsidentialCare + IDEABDiscResCare;
        }
        else {
            Discretionary = LocalTaxSubtraction + IDEABDiscretionaryServicesCost + IDEABDiscResCare;
        }
        IDEABAward = (RelatedServicesCost + ResidentialCare + TotalCostforResPlacement) - Number(Discretionary));
        //IDEABAward = (Number(RelatedServicesCost) + Number(ResidentialCare) + Number(TotalCostforResPlacement)) - Number(Discretionary));
        document.getElementById('<%= DiscretionaryTotal.ClientID %>').value = Discretionary;
        document.getElementById('<%= IdeaBAward.ClientID %>').value = IDEABAward;
    }


    //]]>
</script>




    <td>
        <hcf:CurrencyBox ID="LocalTaxShareSubtraction" OnBlur= "updateFiscalGrid();" Precision="2" runat="server" />
    </td>
like image 614
Adam A Avatar asked Feb 10 '17 22:02

Adam A


People also ask

Why is my function not defined?

If you still get Function not defined then do the following: If you use a master page, make sure you are not placing the reference of the script page inside the container tags (which get overwritten with the actual page content, this is from personal experience lol) I just came to say I resolved it. It was an extra parenthesis

How to fix “JavaScript reference error is not defined”?

“JavaScript Reference Error is Not Defined” As mentioned, there are times in which simply defining a variable will resolve the issue. For example, given the example with jQuery above, we can make a call to noConflict() to restore the variable. Old references of $ are saved during jQuery initialization; noConflict() simply restores them.

What does the error [variable] is not defined mean?

Reference Error [variable] is not defined. In some cases, this can be simply referring to a variable that isn’t defined (perhaps the most popular is when jQuery’s $ function has been dereferenced and you’re trying to use $) and simply needs a definition. But, in other cases, there are times where it may not be as simple.

What does it mean when reference is not defined?

Reference Error is not defined. In some cases, this can be simply referring to a variable that isn’t defined (perhaps the most popular is when jQuery’s $ function has been dereferenced and you’re trying to use $) and simply needs a definition.


2 Answers

Using browser development tools see if you can call the function manually from the console. If you still get Function not defined then do the following:

  • Check for typos
  • If you use a master page, make sure you are not placing the reference of the script page inside the container tags (which get overwritten with the actual page content, this is from personal experience lol)
  • Clear your cache and reload the page
like image 92
Jimmy Hodgson Avatar answered Oct 22 '22 02:10

Jimmy Hodgson


This also happened because I was trying to call a function which had a same variable name.

var fun = fun()

like image 6
Deke Avatar answered Oct 22 '22 01:10

Deke