Open Bug 293397 Opened 20 years ago Updated 2 years ago

document.forms['formname'] doesn't return list if multiple forms have that name

Categories

(Core :: DOM: Core & HTML, defect, P5)

defect

Tracking

()

People

(Reporter: kapil_g83, Unassigned)

References

()

Details

(Keywords: sec-other, Whiteboard: [sg:nse])

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Build Identifier: Mozilla/5.0

Consider the following demo example.it has two codes the first is the Example-
1,is the html file,in which their are two forms with same name as <form 
name="same">on click of Form1 javascript function clickme() is called which 
takes two arguments as shown in the code.the argument is passed as 
clickme(document.forms['same'][0].hidden1,document.forms['same']
[0].hidden1.value).for IE Browser in the javascript function,these values are 
properly shown in the alert box ,but for mozilla it throws the following error 
in the javascript console
(Error: document.forms.same[0].hidden1 has no properties
Source File: javascript:clickme(document.forms['same']
[0].hidden1,document.forms['same'][0].hidden1.value);
Line: 1)
Below are the two demo files code.the first is the Example-1.save it as a html 
file.the second is the Example-2 javascript file.Save it as appvalidation.js


Example-1 (html file)
----------
<html>
<head>
<script language="javascript" src="appvalidation.js">
</script>
</head>
<body>
<form name="same" id="form1">
<input type="hidden" name="hidden1" value="1">
<a href="javascript:clickme(document.forms['same'][0].hidden1,document.forms
['same'][0].hidden1.value);">Form1</a>
</form>
<form name="same" id="form2">
<input type="hidden" name="hidden2" value="2">
<a href="javascript:clickme(document.forms['same'][1].hidden2,document.forms
['same'][1].hidden2.value);">Form2</a>
</form>
</body>
</html>
-------------------------------------------------------------------------------
Example-2 (javascript file)
----------
var isIE = true;

if (navigator.appName.toLowerCase().indexOf("explorer") > -1) {

   isIE = true;
} else{

	isIE = false;
}

function clickme(obj,vals)
{
if (isIE) {
	alert("IE");
	alert(obj);
	alert(vals);
 } else{
	alert("Mozilla");
	alert("IE");
	alert(obj);
	alert(vals);
    }
}




Reproducible: Always

Steps to Reproduce:
1.Explained in the Details Section
2.
3.

Actual Results:  
Explained in the Details Section

Expected Results:  
The values should have been properly alerted in the javascript function call.
Not a security exploit, clearing security flag.

The IE behavior is probably non-standard DOM, but bumping to that component in
case we want to emulate it anyway.
Assignee: nobody → general
Group: security
Component: Form Manager → DOM: Level 0
Product: Firefox → Core
QA Contact: form.manager → ian
Whiteboard: [sg:nse]
Version: unspecified → Trunk
So in IE document.forms['x'] looks for forms names 'x' and if there is more than
one returns a list (not just the first one as we do).  This is indeed
non-standard DOM; is this at all widely used?
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: On click Of the Header it calls a javascript function which take two arguments from the html form → document.forms['formname'] doesn't return list if multiple forms have that name
This seems like a resonable thing to do since we do the same for
myForm.elements['x']
(In reply to comment #3)
> This seems like a resonable thing to do since we do the same for
> myForm.elements['x']

They both should be HTMLCollections. Why the difference?

We have several classes implementing HTMLCollection, since they actually have
very different behavior (in terms of maintaining them live against the DOM,
ownership, object identity, etc).  And yes, some HTMLCollections (eg the return
value of getElementsByTagName) don't really have this "named items end up in a
list" thing.
There are other bugs on similar things. I tried to define how it all works when
I was doing HTMLCollection in WF2, but couldn't find a sane pattern to specify.
If you work out what the DOM0 definition for all this should be, let me know and
I can add it to WA1 when I specify HTMLCollection. Maybe I can even split
HTMLCollection into several variants, like HTMLCollectionGroupDuplicates, 
HTMLCollectionFirstOnly, or HTMLCollectionCrashOnClash.
Assignee: general → nobody
QA Contact: ian → general
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.