[Javascript] A loop for this script?

Paul Novitski paul at novitskisoftware.com
Fri Jul 1 11:42:42 CDT 2005


At 08:34 AM 7/1/2005, Roland Dong wrote:
>Sorry, my mistake, I should say I tried document.getElementById("'
>+ids[x]+'") and document.getElementById(ids[x]) and none of them works. Why
>can't I get the value from the array?

Roland,

Your use of quotation marks is very strange.  Anything inside quotation 
marks is processed as a string and not evaluated [unless you use the eval() 
function which I recommend you approach very warily].  I recommend you 
re-read javacript syntax documentation such as:
http://www.croczilla.com/~alex/reference/javascript_guide/

Are you trying to force javascript to interpret ids[x] as a string?  If so, 
perhaps try this:

         document.getElementById("" + ids[x] + "")

You can probably get to the root of the problem simply by displaying the 
current value of ids[x] on each iteration.  Insert this into your loop:

         alert(x + ": ids[x] = " + ids[x]);

Without studying your code, my guess is that either ids[x] is not a string 
but rather an object or a numeric, or that the subscript x takes the array 
past the last member that has a valid value for your purposes.

Good luck,
Paul 





More information about the Javascript mailing list