Closed Bug 123823 Opened 23 years ago Closed 23 years ago

getElementById returns original value every time.

Categories

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

x86
Windows 98
defect
Not set
major

Tracking

()

VERIFIED INVALID

People

(Reporter: adin, Assigned: jst)

Details

Attachments

(1 file)

The getElementById command will return the original value of a form field even if the user changed the value. See the following code: <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <div id="DivMinBid"><input type="text" id="MyTextField" name="AuctionFirstBid" value="5"></div> <a href="#" onclick="bubu()">Hit Me</a> <P>&nbsp;</P> <script language="JavaScript"> function bubu() { alert(document.getElementById("MyTextField").getAttribute("value")); } </script> </BODY> </HTML> Whenever the user hits the 'Hit Me' link an alert will show the number 5 no matter what the user types in the textfield. In IE hitting the 'Hit Me' link returns the current value in the textfield
Actually this is not a bug, it's by design. To get the *actual* value of a textfield, you have to get its "value" property, not attribute. The "value" attribute of a textfield is the same as its .defaultValue property. If you change alert(document.getElementById("MyTextField").getAttribute("value")); to alert(document.getElementById("MyTextField").value); it will work fine. Marking INVALID.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Verified invalid, is returning defaultvalue as expected.
Status: RESOLVED → VERIFIED
Component: DOM: Core → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: