JavaScript variable name and HTML input name attribute: namespace collision?

Go To


In an HTML file I have the following:

<input type="..." name="myInput1" />

In a corresponding JS file I have the following variable which will hold the string value of that input after blur:

var myInput1;

Is there any problem in having these two identical names? I'm guessing that the namespaces are separate so it is ok.

2012-04-03 21:34
by The111


Short answer, no problem whatsoever.

2012-04-03 21:38
by elclanrs


A short answer is, indeed, no. However, it also greatly depends on how you use the variable. Let's consider that you use javascript for validating that the variable is set as follows:

if(myInput1) {do something}

If you also decide to set the id to be the same as the name is as follows (cause you didn't specify that, it can be anything):

<input type="myInput1" name="myInput1" />

your variable myInput1 will be set to contain the DOM element and won't be empty anymore.

This link between JS and HTML is not only interesting but can be used to create an exploit as described in the section 3.1.2 of Postcards from the post-XSS world (that's where I have the idea from - and yes, it still works even though the article is from 2011).

2017-06-14 08:57
by vanomart