Skip to main content
WolfShade
Legend
July 9, 2020
Question

Curious about something, browsers and JavaScript

  • July 9, 2020
  • 2 replies
  • 357 views

Hello, all,

 

I just learned something interesting about FireFox and JavaScript, and I'm curious if other browsers do the same.

 

I am working on a POC for adding to an existing project, later.  A form with five input type="text", and a textarea.  The inputs are all named 'cct_' where the _ represents a number, 0-4.  There are also two spans after each input, one to indicate success, the other to indicate fail.

 

In JavaScript, I had manually created an array for the inputs:

 

 

 

var ccThese = [].slice.call(document.querySelectorAll('[name=ccThese]');
ccThese.forEach(function(ele,ind){ window['cct' + ind] = ele; });
//Creates an array, then creates a global variable that points to each element.

 

 

 

But I didn't do the same for the spans.  Didn't even think of it.  But, later in the code, I have something like:

 

 

 

window['cct' + i].classList.remove('malAddress');
window['mal' + i].style.visibility='hidden';
window['bueno' + i].style.visibility='hidden';

 

 

 

It works with mal0 through mal4, and bueno0 through bueno4, even though I did not expressly create them.  So, using "window['elementName']" will point to said element, even though I didn't create that variable.

 

So, my question is:  Do all browsers do this?  Or is it just FireFox?

 

V/r,

 

^ _ ^

This topic has been closed for replies.

2 replies

WolfShade
WolfShadeAuthor
Legend
July 10, 2020

Hi, BKBK,

 

Problem is, SO is more of a popularity contest than an actual support forum.  Yes, I have occasionally gleaned some information from answers, there.  But there are so many threads that are downvoted just for the sake of downvoting.  I no longer consider SO to be a consistant source of help.  I deleted my account three days after I created it, and that was years ago.  But, thank you for the suggestion.

 

V/r,

 

^ _ ^

BKBK
Community Expert
Community Expert
July 11, 2020

Fair enough.

BKBK
Community Expert
Community Expert
July 10, 2020

Hi WolfShade,

Ain't got no answers, just a suggestion. You might get more mileage on this from StackOverflow.