• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

javascript - reserved variable names

Special K

Diamond Member
Let me start by saying that I am a complete HTML/JS n00b and just started messing around with this stuff today. I am not a web or software developer - I just need to create a functional webpage used for tracking data.

That said, I am currently experimenting with Javascript and am wondering why the following code does not work:

But the following does:

In the first case, clicking the button causes the popup alert box to appear. In the second case, the box does not appear, and windows reports the following JS error:

"Error: 'document.data_version_form.menu_value.value' is null or not an object"

It seems to have something to do with the fact that the text "form" appears in the name of the form. If I change that text to anything else, it works. For example, I can do:

<form name = "data_version_from">

as in example 2 below, and it will work.

At first I suspected that this was some keyword or reserved word, but then I looked at a list of all reserved javascript words:

link

and found that I could replace the "form" text with other supposedly reserved words such as "blur" and "frame", and the example would still work. Plus I thought reserved words could appear within larger words - it is only when they are used alone that they can cause an error.

What is going on here?

EDIT: something seems to be wrong with the spacing in my code
 
Both your working and non-working examples appear to be identical to me. . .😕

Did you make a copy-paste error or something? I think you accidentally pasted in the working example for both.
 
Originally posted by: ahurtt
Both your working and non-working examples appear to be identical to me. . .😕

Did you make a copy-paste error or something? I think you accidentally pasted in the working example for both.

They differ only by the form name

<form name = "data_version_form">
<form name = "data_version_from">
 
Originally posted by: MrChad
Originally posted by: ahurtt
Both your working and non-working examples appear to be identical to me. . .😕

Did you make a copy-paste error or something? I think you accidentally pasted in the working example for both.

They differ only by the form name

<form name = "data_version_form">
<form name = "data_version_from">

ahahah I do that all the time.
 
Originally posted by: Chosonman
Originally posted by: MrChad
Originally posted by: ahurtt
Both your working and non-working examples appear to be identical to me. . .😕

Did you make a copy-paste error or something? I think you accidentally pasted in the working example for both.

They differ only by the form name

<form name = "data_version_form">
<form name = "data_version_from">

ahahah I do that all the time.

So is that not allowed or what? I can't the "form" one to work under IE or FF. FF just does nothing, and IE does nothing and reports a javascript error, as described above.
 
Argh, nevermind, I'm a moron. It wasn't working because I already had another form defined in the code with the exact same name. It was way down the page and I forgot about it.

You'd think JS could give a more descriptive error message like "variable already defined" or something.


Argh, it's always the stupid mistakes that take the longest to find.
 
Back
Top