Closed
Bug 324262
Opened 19 years ago
Closed 19 years ago
Very simple html FORM is not visible to javascript
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 178258
People
(Reporter: peterd, Unassigned)
Details
Attachments
(2 files)
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8) Gecko/20051111 Firefox/1.5 A simple HTML form is not visible to javascript .. referencing via document.forms[0]..etc acts as if the form object does not exist. It works if text is entered anywhere in the form block and some form objects will make it work for example a SELECT list. Reproducible: Always Steps to Reproduce: 1. Run this block of code: <FORM METHOD=POST ACTION=test.html> <INPUT NAME=testme> <INPUT TYPE=HIDDEN NAME=CountryID VALUE=840> <INPUT TYPE=HIDDEN NAME=GroupID VALUE=1> </FORM> <SCRIPT> alert(document.forms[0].CountryID.value); </SCRIPT> To get it to work one just needs to include text inside of the FORM block or use certain types of html form controls. Actual Results: No alert pop up box, javascript error in console Error: document.forms[0] has no properties. Expected Results: Alert popup should spit out "840" It's easy to workaround but it seems some web applications folks can't modify are using just such a scheme.
Comment 1•19 years ago
|
||
Works for me, please attach a minimized testcase showing this issue: https://bugzilla.mozilla.org/attachment.cgi?bugid=324262&action=enter
Reporter | ||
Comment 2•19 years ago
|
||
(In reply to comment #1) > Works for me, please attach a minimized testcase showing this issue: > https://bugzilla.mozilla.org/attachment.cgi?bugid=324262&action=enter This is the simplest case I could make to show the problem: <FORM METHOD=POST> <INPUT TYPE=HIDDEN NAME=CountryID VALUE=840> </FORM> <SCRIPT> alert(document.forms[0].CountryID.value); </SCRIPT> I've tried this with mozilla 1.5, 1.0.7 and 1.0.4 on the linux platform and they all give the same results.
Comment 3•19 years ago
|
||
This works for me, i get an alert saying "840"
Comment 4•19 years ago
|
||
WFM on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20060120 Firefox/1.6a1
Updated•19 years ago
|
Attachment #209242 -
Attachment description: Reporter's testcase → Cleaned-up testcase
Comment 5•19 years ago
|
||
...but this one doesn't WFM. Note: I renamed my above testcase to "Cleaned-up testcase."
Comment 6•19 years ago
|
||
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.9a1) Gecko/20060120 SeaMonkey/1.5a reporter's testcase is wfm, the "cleaned-up testcase" is made from it by removing HTML, head and body tags, and tags capitalized: <FORM METHOD=POST> <INPUT TYPE=HIDDEN NAME=CountryID VALUE=840> </FORM> <SCRIPT> alert(document.forms[0].CountryID.value); </SCRIPT> That testcase didn't work and was showing a warning and an error in JS console. I pasted it into the body of an empty HTML sheet in composer, saved and loaded it from disk into the browser, was working. Reloading the original "Cleaned-up" testcase was now working too, but gave another message in JS Console, not the original messages: Error: [Exception... "'Permission denied to get property XULElement.accessKey' when calling method: [nsIDOMXULLabelElement::accessKey]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: https://bugzilla.mozilla.org/attachment.cgi?id=209242 :: <TOP_LEVEL> :: line 9" data: no] Source File: https://bugzilla.mozilla.org/attachment.cgi?id=209242 Line: 9
Reporter | ||
Comment 7•19 years ago
|
||
The thing is that it works as long as you save it from the html editor because the editor changes the data and adds the BODY tag. With the BODY tag the problem goes away. To reproduce you need to create a raw file with just the data in my test case and *nothing* else around it.
Comment 8•19 years ago
|
||
(In reply to comment #6) > Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.9a1) Gecko/20060120 SeaMonkey/1.5a > > reporter's testcase is wfm, the "cleaned-up testcase" is made from it by > removing HTML, head and body tags, and tags capitalized: I think you've got them reversed. ;)
Comment 9•19 years ago
|
||
For clarity, the reason I provided two testcases is to show that the problem doesn't occur with HTML that is closer to valid (ie. lowercase tags, double-quoted attribute values, html and body tags, etc.) than what the reporter explicitly provided. So this would appear to be an issue with interpretation of invalid HTML, maybe? Then again, should we even try to compensate for such invalidity and leave it up to standards evangelism to get people not to write code like this?
Comment 10•19 years ago
|
||
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.9a1) Gecko/20060120 SeaMonkey/1.5a Cleaned-Up testcase is nearly validating, adding title and doctype made it validating, but didn't change the behavior. Cleaned-up testcase: shows Alert 840 https://bugzilla.mozilla.org/attachment.cgi?id=209242 view-source:https://bugzilla.mozilla.org/attachment.cgi?id=209242 first-time alert: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line 686" data: no] now I'm getting reproducible: Error: [Exception... "'Permission denied to get property XULElement.accessKey' when calling method: [nsIDOMXULLabelElement::accessKey]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: https://bugzilla.mozilla.org/attachment.cgi?id=209242 :: <TOP_LEVEL> :: line 9" data: no] Source File: https://bugzilla.mozilla.org/attachment.cgi?id=209242 Line: 9 Reporter's testcase: (without html + body tags) https://bugzilla.mozilla.org/attachment.cgi?id=209243 view-source:https://bugzilla.mozilla.org/attachment.cgi?id=209243 Warning: reference to undefined property document.forms[0] Source File: https://bugzilla.mozilla.org/attachment.cgi?id=209243 Line: 6 Error: document.forms[0] has no properties Source File: https://bugzilla.mozilla.org/attachment.cgi?id=209243 Line: 6 <FORM METHOD=POST> <INPUT TYPE=HIDDEN NAME=CountryID VALUE=840> </FORM> <SCRIPT> alert(document.forms[0].CountryID.value); </SCRIPT>
Comment 11•19 years ago
|
||
DUP of Bug 178258
Comment 12•19 years ago
|
||
*** This bug has been marked as a duplicate of 178258 ***
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•