1

I have this code and works well;

 $(".campodigitavel").change(function(){ $(".campocalculado").each(function(){ if ($(this).attr("ordem") == 1){ // O valor do primeiro item do grupo será o campo base para o cálculo. lnTotal = $(this).val(); } // Percorre todos os filhos cujo pai é o atual da iteração $("[pai=" + $(this).attr("id") + "]").each(function(){ if(this.value != ""){ lnTotal = eval(lnTotal + "" + $(this).attr("operador") + "" + parseFloat(this.value)); } }); $("#" + $(this).attr("target")).val(lnTotal); }); }); 

But, when I alter the code adding the a function call like this:

$(".campodigitavel").change(function(){ $(".campocalculado").each(function(){ if ($(this).attr("ordem") == 1){ // O valor do primeiro item do grupo será o campo base para o cálculo. lnTotal = $(this).val(); } // Percorre todos os filhos cujo pai é o atual da iteração $("[pai=" + $(this).attr("id") + "]").each(function(){ if(this.value != ""){ lnTotal = eval(lnTotal + "" + $(this).attr("operador") + "" + parseFloat(this.value)); } }); $("#" + $(this).attr("target")).val(lnTotal); }); calcularPercentual(); }); 

The function code:

function calcularPercentual(){ var lnValorReferencia, lnValorPai lnValorReferencia = $("[percentual=true]").val(); $('.perccalculado').each(function(){ lnValorPai = $("#" + $(this).attr("pai")).val(); if(lnValorPai != ""){ $(this).val(lnValorPai * 100 / lnValorReferencia); } }); } 

When the JQuery Code execute in second time, appear the error: Uncaught SyntaxError: Unexpected token ILLEGAL.

Why?

Thanks, Luciano

4
  • Can you show the HTML for the objects matching the '.perccalculado' selector (those with 'perccalculado' as the class)? Commented Dec 29, 2011 at 20:17
  • <input type="text" id="delegadoperc" size="5" class="perccalculado" pai="delegado" readonly> <input type="text" id="presidenteperc" size="5" class="perccalculado" pai="presidente" readonly> <input type="text" id="hsperc" size="5" class="perccalculado" pai="hs" readonly> A total of 11 fields. Commented Dec 30, 2011 at 13:24
  • The entire code is here gist.github.com/1539856 Commented Dec 30, 2011 at 13:30
  • The complete error in console of Crhome: Uncaught SyntaxError: Unexpected token ILLEGAL (anonymous function)TelaFixacaoMetas.html:56 e.extend.eachjquery-1.7.1.min.js:2 e.fn.e.eachjquery-1.7.1.min.js:2 (anonymous function)TelaFixacaoMetas.html:54 e.extend.eachjquery-1.7.1.min.js:2 e.fn.e.eachjquery-1.7.1.min.js:2 (anonymous function)TelaFixacaoMetas.html:49 f.event.dispatchjquery-1.7.1.min.js:3 f.event.add.h.handle.i Commented Dec 30, 2011 at 14:42

4 Answers 4

2

add (;) after var lnValorReferencia, lnValorPai;

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

Comments

1

You forgot semicolon (;) after initializing var lnValorReferencia, lnValorPai

Comments

1

I discover the erro after read this topic ( http://forum.jquery.com/topic/chrome-uncaught-syntaxerror) I open the page in firefox and it show me the true error.

I changed the name of atribute pai to paiperc on the fields with class="perccalculado".

Comments

0

Maybe try putting a semi-colon after the line:

var lnValorReferencia, lnValorPai 

I'm kinda doubtful on this since js does a lot of implicit semicolon insertion, but worth a try

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.