Closed
Bug 590363
Opened 15 years ago
Closed 15 years ago
Input element created in JavaScript loses its assigned value when the type is changed to 'hidden'
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla2.0b7
| Tracking | Status | |
|---|---|---|
| blocking2.0 | --- | betaN+ |
People
(Reporter: ruddzw, Assigned: mounir)
References
Details
(Keywords: regression)
Attachments
(2 files)
|
386 bytes,
text/html
|
Details | |
|
6.13 KB,
patch
|
sicking
:
review+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4
Build Identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b4) Gecko/20100818 Firefox/4.0b4
In Firefox 4, if you create an input element in JavaScript, and give it a value, then give it a type of 'hidden', the value will change to the empty string.
Reproducible: Always
Steps to Reproduce:
1. var in = document.createElement('input');
2. in.name = 'myname';
3. in.value = 'myval';
4. in.value // => 'myval'
5. in.type = 'hidden';
6. in.value // => ''
Actual Results:
The value of the created input element was an empty string.
Expected Results:
The value of the created input element is the assigned value.
Workaround: assign the 'type' attribute before you assign the 'value' attribute.
Comment 1•15 years ago
|
||
Comment 2•15 years ago
|
||
Our current behavior is what the HTML5 spec calls for as far as I can see. In particular, setting .value on a _text_ input (as here) sets the value but not the attribute named "value". Changing the type doesn't change anything about this situation... but for hidden inputs getting the "value" property gets the string currently in the "value" attribute, which is not set.
We used to do some weirdness here with setting the "value" attribute when changing the type; it looks like Opera and Webkit still do that.
Given the likely web compat implications, requesting blocking; this might need a spec change to spec the weird behavior....
Status: UNCONFIRMED → NEW
blocking2.0: --- → ?
Ever confirmed: true
| Assignee | ||
Comment 3•15 years ago
|
||
I talked to Hixie and he told me this was taken into consideration when he wrotes the change and he thinks the specifications shouldn't change/revert. For him, this shouldn't break the web and one of the reasons is IE didn't let the author change the type of an input.
IMO, I'm not sure it will be clear to everyone that:
var input = document.createElement('input');
input.type = 'hidden';
input.value = 'foo';
and:
var input = document.createElement('input');
input.value = 'foo';
input.type = 'hidden';
are not the same thing.
Maybe we could wait and see how bad this change is for the web?
OS: Mac OS X → All
Version: unspecified → Trunk
Comment 4•15 years ago
|
||
> one of the reasons is IE didn't let the author change the type of an input.
At all? Even if you'd just created it with createElement? So you can't create non-text inputs in IE?
IIRC IE allows the type to be changed once for elements created with createElement.
Comment 6•15 years ago
|
||
And in IE, setting .value changes the value attr even for text inputs, right? So in fact the testcase in this bug used to be interoperable in all browsers?
| Reporter | ||
Comment 7•15 years ago
|
||
These are the results of Boris' test case for all browsers I've tested:
IE 6 - 8:
Value: myval
'value' attr: myval
Value after type change: myval
Value attr after type change: myval
Firefox 2.0 - 3.6, Safari, Chrome:
Value: myval
'value' attr: null
Value after type change: myval
Value attr after type change: myval
Firefox 4.0:
Value: myval
'value' attr: null
Value after type change: null
Value attr after type change: null
To be honest, I had not realized that setting .value and setting the value attr were different things. That is, I didn't realize that every browser wasn't doing what IE is doing. It appears that by changing the type and triggering the "weirdness" we ended up with some code that isn't supposed to work but does in all major browsers.
I would imagine most of the web would not break, but changing the type of an input once from text to something else, which in my opinion would be the default use case of changing the type, definitely works in IE. I guarantee there are *some* sites out there that will break.
Comment 8•15 years ago
|
||
I think this needs to block a beta....
This is a regression from 3.6, right? Making this block betaN as I suspect we'll revert to something closer to what we used to do, which shouldn't be too risky, right?
Let me know if you think it should get more testing than that.
blocking2.0: ? → betaN+
Keywords: regression
Comment 10•15 years ago
|
||
Yes, definitely regression since 3.6.
BetaN should be ok, I think.
Reverting back might be risky, because we don't want to (for now, pending spec changes) actually revert to the behavior we used to have....
Comment 11•15 years ago
|
||
I just talked to hixie about this. He's planning to change the spec to something closer to what we used to do (which itself was similar to what webkit does).
Comment 12•15 years ago
|
||
| Assignee | ||
Updated•15 years ago
|
Assignee: nobody → mounir.lamouri
| Assignee | ||
Comment 13•15 years ago
|
||
There is still one case where the value is going to be reset to the empty string even with the specification change:
var e = document.createElement('input');
e.type = 'text';
e.value = 'foo';
e.type = 'file';
e.type = 'text;
-> e.value == ""
In one hand, I don't think this is going to break anything. In another hand, it feels weird that we are net resetting the value except for type='file'.
I'm not going to ask a specification change but I wanted to point this.
Attachment #472041 -
Flags: review?(jonas)
| Assignee | ||
Updated•15 years ago
|
Status: NEW → ASSIGNED
Comment 14•15 years ago
|
||
I think that's the desired behavior.
Attachment #472041 -
Flags: review?(jonas) → review+
| Assignee | ||
Comment 16•15 years ago
|
||
Pushed:
http://hg.mozilla.org/mozilla-central/rev/7a5fed78b780
Thank you for your report Rudd :)
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b6
You need to log in
before you can comment on or make changes to this bug.
Description
•