Within a function, I am creating a new variable that contains an HTML element. The variable declaration works fine in Firefox for example, however it comes up "undefined" in Google Chrome.

function updateName(num)
{
	name = document.getElementById("id_name_"+num);
}

Recommended Answers

All 5 Replies

Hard to see why Chrome should not handle this. You could try changing the id's prefix, eg:

function updateName(num)
{
  name = document.getElementById("myRef_"+num);
}

The variable should also be localised:

function updateName(num)
{
  var name = document.getElementById("myRef_"+num);
}

otherwise a global variable is created. Do this instead:

function updateName(num)
{
  return document.getElementById("myRef_"+num);
}

and use the returned value wherever it is needed, or store it non-globally.

It is bad practise to pass data via the global namespace, though this does not explain the difference between Chrome and other browsers.

Airshow

im still having problem about that:(

It has been reported several times that Google Chrome has some issues with Javascript...
I don`t any too much javascript so I am not able to say for sure...but the browser could be the problem...

It turns out I noobed out lol.

"name" and "class" are reserved names that apparently Firefox doesn't mind but Chrome didn't like.

Thanks for all your input (and the tips Airshow) :)

Zurompeta,

noobed out

:icon_biggrin:

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.