What can I do not get this to work in Firefox?

document.getElementById("type_" + x).checked

When I used

alert(document.getElementById("type_" + x).checked);

to check the value it comes up fine in IE, but I get a "has no properties" error in FireFox.

Recommended Answers

All 2 Replies

There are several possibilities, but I need to see more to tell what. The possibilities:

1. IE is not case sensitive for styles and tags. Firefox is case-sensitive. So, to be sure your ids and styles are compatible, make everything in your stylesheet and references lowercase.

2. It may depend on the browser whether it is looking for the name attribute or the id attribute. For Input boxes, it is best to provide both. But remember that all radio buttons in a group require the same name, but different ids.

3. Check for accidental capitalizations and typos.

4. Do you accidentally have two objects with the same id attribute? Do you have a different object with a name attribute which is the same as the id attribute you are using?

5. Remember that the checked attribute is boolean.

6. Are the contents of the variable x known to be a string? If not, are they known to be an integer? You may have an issue with roundoff error if the value is calculated.

7. Did you return x from a function? If so, it may be that you used a parameter passing method that returns a value on one browser, but not on another.

8. How did you declare x? It may be that, under the rules of one browser, x is outside its scope.

9. Could x have a leading blank for some reason?

10. I was told to use single quites for JavaScript strings, and double quotes for html attributes. I don't think this is a hard rule, but it might be confusing something.

Try doing this:

strig = 'type_' + x;
alert(strig);
alert(document.getElementById(strig).checked);

Look at strig and see what it really is.

Midi magic ! you are a G-D!!
thanks for the tip

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.