A função JavaScript não é um erro definido (mas está definida)

Tenho uma função JavaScript que dispara no borrão. Estranhamente, funcionou bem na primeira vez que eu corri, e desde então eu tenho recebido um erro que diz função JavaScript não definida-e ele pára de funcionar. Procurei no Google problemas semelhantes, mas nenhum dos conselhos foi capaz de resolver a questão. Asp.Net 3.5 Webforms, se for importante. Incluí algumas funções adicionais e linhas de código que podem não estar relacionadas com o problema. A questão que estou a ter diz respeito updateFiscalGrid, a grande função. O HTML que se liga ao evento está abaixo da função.

<%@ 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>
Author: mason, 2017-02-11

6 answers

Usando ferramentas de desenvolvimento do navegador, veja se pode ligar a função manualmente a partir da consola. Se ainda tiver a função não definida, então faça o seguinte:

  • verifica se há erros de Digitação
  • se usar uma página principal, certifique-se de que não está a colocar a referência da página do programa dentro das marcas do contentor (que são sobrepostas com o conteúdo da página actual, isto é por experiência pessoal lol)
  • limpa a tua 'cache' e recarrega a Página
 3
Author: Jimmy Hodgson, 2017-02-10 22:48:09

O que me deixa perguntar é que eu tinha um empty function no meu espaço de nomes

E quando eu {[2] } essa função, eu tinha isto {[3] } que faz com que toda a página pare de funcionar

TypeError: MyNamespcae.myFunction is not a function

Por isso, não crie uma função vazia, adicione uma declaração como a sem efeito (0); ou devolva null;

 1
Author: Basheer AL-MOMANI, 2018-05-22 13:13:44
No final do dia, o código do lado do servidor não importa. Podia ter sido escrito em qualquer outra língua do lado do servidor.

Se está a ver esse erro no navegador, precisa de verificar o código javascript que foi gerado pelo seu código do lado do servidor.

Uma vez lá você será capaz de ver se a função está realmente definida ou não. Se não, algo está errado com a geração de código javascript do lado servidor.

 0
Author: Mestre San, 2017-02-13 15:08:32

Provavelmente é por isso que: ReferenceError: a função não é definida com o onclick

Como Resposta Curta: "nunca uses .onclick (), ou atributos semelhantes [onblur ()] de um userscript!"

 0
Author: peterPP1, 2017-08-05 21:14:58
Eu tinha o mesmo problema. Eu tinha colocado uma função dentro do $(document).ready(function() {});. Tudo o que tinha de fazer era tirar a minha função dela. Agora está a funcionar como um encanto.
<button onclick="event.preventDefault(); myFunction(this);">Submit post</button>

<script type="text/javascript">
    $(document).ready(function() {
        // Some stuff
    });

    myFunction(object) {
        // Some other stuff
    }

</script>
 0
Author: Jeroen Bellemans, 2018-06-23 07:59:32
Isso também aconteceu porque eu estava tentando chamar uma função que tinha o mesmo nome variável.

var fun = fun()

 0
Author: Deke, 2018-08-19 13:40:32