I am maintaining many old websites and CMS systems at my new job and run into an issue with one. The ASP site is using JavaScript and this line stopped working today (or slightly earlier than today):
document.forms(0)
Console would report Uncaught TypeError: document.forms is not a function
. After Googling, I found that I can replace it with:
document.forms[0]
and continue moving forward, however, this website and files are littered with this reference.
Can anyone find explain what might have happen? Chrome, IE and Firefox are not working, was there an update to browsers or JavaScript? I can't seem to find document.forms(0)
in my searches. Odd.
I am maintaining many old websites and CMS systems at my new job and run into an issue with one. The ASP site is using JavaScript and this line stopped working today (or slightly earlier than today):
document.forms(0)
Console would report Uncaught TypeError: document.forms is not a function
. After Googling, I found that I can replace it with:
document.forms[0]
and continue moving forward, however, this website and files are littered with this reference.
Can anyone find explain what might have happen? Chrome, IE and Firefox are not working, was there an update to browsers or JavaScript? I can't seem to find document.forms(0)
in my searches. Odd.
- I don't think any other browser ever supported that. – Bergi Commented Jul 13, 2017 at 3:03
- 1 If the ASP site was only ever expected to work in IE, then I can see why they'd have done this. Otherwise, square brackets are correct and parentheses are wrong. There's not going to be a way to fix this for Chrome / Firefox, etc - parentheses are used for function invocation, not array access. – g.d.d.c Commented Jul 14, 2017 at 20:38
- You might want to put your edits as an answer – Bergi Commented Jul 14, 2017 at 20:48
- Just did @Bergi, thanks. I haven't been posting to this site for too long. – Derek Commented Jul 14, 2017 at 20:59
1 Answer
Reset to default 6I will post the answer that I have thus far and like the ments mention, this is not a standard for all browsers, it will work in IE, but generally nothing else:
document.forms(0) //IE only
This is the proper way:
document.forms[0] //All browsers (including IE)
I was able to find ONE article (Mozilla developer network) that references the round-brackets (link) saying that document.forms(0)
is IE-specific ways to access elements
and document.forms[0]
is the W3C web standards replacements
.
To confirm, I did some testing with BrowserStack
and noticed that all versions of IE
were working, nothing else worked except for Chrome
version 15 and 16 (first two versions that BrowserStack has on their system for XP
).
Use the following code or your website will only be IE patible: document.forms[0]
Maybe my Client was always using IE and just switched to Chrome or something else. I haven't confirmed that yet, more does the site have any time of Analytics.