Closed Bug 460955 Opened 16 years ago Closed 16 years ago

Form element still present in document.formname.name after being removed from DOM tree

Categories

(Firefox :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 307415

People

(Reporter: dcviana, Unassigned)

Details

(Keywords: testcase)

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; pt-BR; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; pt-BR; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3

If I have a table and inside one of its cells I have an element (like an input of type TEXT for example) and I remove the row the cell is in using "deleteRow(lineNumber)", I still can access the element by document.forms[0].elementName.

Calling "typeof" on it still registers as "object" and it is not NULL.
If instead I give an ID to the element and call it by document.getElementById("elementId") it's typeof registers as "object" but it is NULL now.

This only happens if I access the element before the row removal and after the line removal. If I simply remove the line it doesn't happens. It's like if I access the element before the line removal, Firefox keeps some kind of link to the element allowing me to still access it.

Reproducible: Always

Steps to Reproduce:
1.Create a new HTML page and create a form using the FORM tag
2.Create a table inside the form and give it an ID of "myTable". Insert one row and one cell in it.
3.Inside the cell, insert the tag <input type="text" name="myElement" id="myElement" />
4. Create a script and create a function. Write the following code:

function myFunction(){
  //Access the element before the line removal, any access works, even alerting it
  alert(typeof(document.forms[0].myElement));
  alert(document.forms[0].myElement);

  var aTable = document.getElementById("myTable");
  aTable.deleteRow(0);
  
  //After the line removal, I can still access the element using document.forms[n]
  alert(typeof(document.forms[0].myElement));
  alert(document.forms[0].myElement);

  //But I can't access it using getElementById (element is null)
  alert(typeof(document.getElementById("myElement")));
  alert(document.getElementById("myElement"));
}

5. Add a button somewhere to call the function and press it.
Actual Results:  
You will notice that the element accessed by document.forms[n] is still valid but accessing it by getElementById gives a NULL element.
You'll also notice that if I comment the first two alerts the script behave as espected, giving "undefined" when accessing by document.forms[n] and "NULL" when I access by getElementById

Expected Results:  
After removing a row from a table, all elements contained inside that row must be removed from the DOM tree and invalidated.

The simple workaround for this problem is always test if an element exists by using getElementById and verifying if the result is NULL.

Nonetheless, old webpages and web based systems may show strange behaviour if they have scripts writen with the features I have showed.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: testcase
OS: Linux → All
Hardware: PC → All
Summary: Javascript: Element still present in DOM tree after deleting it from inside a table. → Form element still present in document.formname.name after being removed from DOM tree
Attached file clearer testcase
Attachment #344077 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: