How to get JavaScript value in PHP?

Javascript: Get previous array element value?

  • I'm trying to do this col[i] = childWidth + col[i-1]; To get the previous array item value, but the output I get for this just says NaN. It works fine when I don't have the -1 in the array brackets. How do I get the previous value?

  • Answer:

    It's hard to say unless you post previous lines but my guess would be childWidth is a number and col[i-1] is undefined. are all elements of your array col defined? Edit: OK, your loop is not posted fully, but assuming you're doing it correctly for(var i = 1; i < some_number; i++) and the line posted in your original post was inside the loop, childWidth should be undefined. Make sure you've defined it somewhere before col[i] = childWidth + col[i-1]; possibly before the loop.

David at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.