Highlighted

Curious about something, browsers and JavaScript

LEGEND ,
Jul 09, 2020

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,

 

^ _ ^

TOPICS
Advanced techniques, Asynchronous, Builder, cfchart, Cffiddle, Connector, Database access, Documentation, Event gateways, Flash integration, Getting started, Monitoring, Reporting, Security, Server administration

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Curious about something, browsers and JavaScript

LEGEND ,
Jul 09, 2020

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,

 

^ _ ^

TOPICS
Advanced techniques, Asynchronous, Builder, cfchart, Cffiddle, Connector, Database access, Documentation, Event gateways, Flash integration, Getting started, Monitoring, Reporting, Security, Server administration

Views

53

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 09, 2020 0
Adobe Community Professional ,
Jul 10, 2020

Copy link to clipboard

Copied

Hi WolfShade,

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 10, 2020 0
LEGEND ,
Jul 10, 2020

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,

 

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 10, 2020 0
BKBK LATEST
Adobe Community Professional ,
Jul 11, 2020

Copy link to clipboard

Copied

Fair enough.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 11, 2020 0