Copy link to clipboard
Copied
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,
^ _ ^
Copy link to clipboard
Copied
Hi WolfShade,
Ain't got no answers, just a suggestion. You might get more mileage on this from StackOverflow.
Copy link to clipboard
Copied
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,
^ _ ^
Copy link to clipboard
Copied
Fair enough.