javascript error - what's missing?

by johlum
4 replies
For the javascript guru's I have a question.

Setting up a .js file to populate data on various pages and I can't figure out what's missing.

Here's the code and the error message I keep getting.

--------------
function linkwrite() {
var link = newArray()
for (x in link) {
element = document.getElementById("link"+x);
url = link[x];
linkText = element.innerHTML;
element.innerHTML='<a href="+url+">'+linkText+'</a>';
}
}

--------------

Problem at line 3 character 6: Bad for in variable 'x'.

for (x in link) {


Any thoughts?

Thanks

Ernie
#error #javascript #missing
  • Profile picture of the author phpbbxpert
    You should define x
    var x;

    but also, how are you populating your object.
    link is an empty array.

    What are you trying to do?
    {{ DiscussionBoard.errors[3036672].message }}
    • Profile picture of the author johlum
      I'm populating the array with links defined this way:

      "http://www.mydomain.com"

      So, what would be the code defining x as a variable?

      Ernie
      {{ DiscussionBoard.errors[3036706].message }}
  • {{ DiscussionBoard.errors[3036736].message }}
    • Profile picture of the author johlum
      Thanks!

      I'll give it a shot and see what happens.

      Ernie
      {{ DiscussionBoard.errors[3036749].message }}

Trending Topics