0

This batch does not work, although I put in all possible checks to know wthere a certain assignment does not come through:

alert("valorsumo = "+valorsumo);  // okay
for (j = 0; j <= "<?php echo $fVN ?>"; j++) {
  horp = valornbroj[j];
  alert("horp = "+horp);  // okay
  elcentoj[j] = Math.round(horp/valorsumo * 1000) / 10;  // percentage with one decimal
  alert("percentage = "+elcentoj[i]);  //  undefined !

The queer thing is that the same kind of code, met in a separate file produces the desired answer:

function het()  {     
  var nbroj = [],
  sumo = 3894,
  elcentoj = [];
  nbroj[0] = "290046";   
  elcentoj[0] = Math.round(nbroj[0]/sumo * 1000) / 10;
  alert("percentage = "+elcentoj[0]);  // okay
}

Am I blind? Thanks in advance !

1
  • 1
    Try changing elcentoj[i] to elcentoj[j] :) Semi-blind :) Commented Dec 28, 2013 at 8:28

1 Answer 1

2

In this line

alert("percentage = "+elcentoj[i]);  

I is not defined replace i with j

alert("percentage = "+elcentoj[j]);

So your loop will be like this

for (j = 0; j <= "<?php echo $fVN ?>"; j++) {
  horp = valornbroj[j];
  alert("horp = "+horp);  // okay
  elcentoj[j] = Math.round(horp/valorsumo * 1000) / 10;  // percentage with one decimal
  alert("percentage = "+elcentoj[j]);  
}
Sign up to request clarification or add additional context in comments.

1 Comment

Shame on me! The wrong index hid the real mistake, which happily I found already: a variable was defined locally, within function het(), while it needed to be passed to another function. Thank you !

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.