Closed
Bug 284471
Opened 20 years ago
Closed 19 years ago
form elements are cleared when innerHTML is appended to
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 159282
People
(Reporter: pbalyoz, Unassigned)
Details
Attachments
(1 file)
|
1.15 KB,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1
When an HTML form contains a DIV tag which has its innerHTML set to some form
elements for the user to modify, if any JavaScript appends to the innerHTML
(such as to add supplemental form elements), all form elements "reset"
themselves, clearing whatever values the user typed in.
This does not happen in IE.
Reproducible: Always
Steps to Reproduce:
1. Save the following HTML to some "file.html", and load it into firefox.
2. Type something into "Full Name 1" input box
3. click the "add another form line" button.
Actual Results:
Notice that what you initially typed in has disappeared.
Go back and try entering something else, or refresh screen, or submit form, to
discover it's not just a rendering problem - the form text you entered is
actually gone.
Examine javascript code to see we never tweak with those original form elements,
we simply append to innerHTML, which should not touch those elements.
Expected Results:
Form elements that are not being touched by an operation in Javascript (because
they're already part of innerHTML before the append) should not be reset.
Try the above steps in IE to see the bug is not there.
HTML for above testing, to reproduce the problem:
<html>
<head>
<script type="text/javascript">
<!--
var numsections = 0;
function initarea() {
document.all.area.innerHTML = "";
numsections = 0;
addsection();
}
function addsection() {
document.all.area.innerHTML += "Full Name " +
(numsections+1) + ": <input name=\"fullname" + numsections + "\"
size=\"40\" /><br>";
numsections++;
}
-->
</script>
</head>
<body bgcolor="#FFFFFF">
<h2>Enter some names</h2>
<form name="theform" method="get">
<div id="area"></div> <br>
<input type="button" value="add another form line"
onclick="addsection()">
<input type="button" value="reset form" onclick="initarea()">
<input type="submit">
</form>
<script type="text/javascript">
<!--
initarea();
-->
</script>
</body>
</html>
Comment 1•20 years ago
|
||
Can confirm this on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3
I can confirm this for Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 Adding to the innerHTML of a div lower or at the same level in hierarchy does not reset the form. Adding to the innerhmtl of the div itself or a div higher in hierarchy does reset the form. The above can be used as a not-so-very-nice way around the problem. (Ie when writing to the innerHTML of a div always create a new div which will be used for the next write action)
Comment 3•19 years ago
|
||
Updated•19 years ago
|
Assignee: bugs → general
Component: Form Manager → DOM: Mozilla Extensions
Product: Firefox → Core
QA Contact: form.manager → ian
Version: unspecified → Trunk
Comment 4•19 years ago
|
||
Probably a dupe of bug 159282.
Comment 5•19 years ago
|
||
Oh, d'oh, foo.innerHTML += "<bar/>" is foo.innerHTML = foo.innerHTML + "<bar/>", and since innerHTML isn't innerDOM you should wind up resetting everything. *** This bug has been marked as a duplicate of 159282 ***
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → DUPLICATE
Updated•12 years ago
|
Component: DOM: Mozilla Extensions → DOM
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•