Closed Bug 82912 Opened 25 years ago Closed 24 years ago

JavaScript function doesn't work if its name is used by form element

Categories

(Core :: JavaScript Engine, defect)

x86
All
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: kazhik, Assigned: rogerl)

Details

Attachments

(1 file)

JavaScript function doesn't work if its name is used by form element. <HTML> <HEAD> <TITLE>Mozilla Testcase(27 May 2001)</TITLE> <SCRIPT type="text/javascript"> function test1() { alert('success'); } function test2() { alert('success'); } </SCRIPT> </HEAD> <BODY> <FORM> <INPUT type=button value=test1 onclick="test1()"> <INPUT type=button value=test2 onclick="test2()"> <INPUT type=checkbox name="test2">this checkbox name is test2. </FORM> </BODY> </HTML> This bug is similar to bug 57626.
Attached file Testcase
HTML Element component is deprecated, and should be removed from Bugzilla. Clayton is not the correct owner for these. Reassigning to layout.
Assignee: clayton → karnaze
Component: HTML Element → Layout
QA Contact: bsharma → petersen
why is this assigned to layout? reassigning to core owner, where it should probably go somewhere else.
Assignee: karnaze → attinasi
Changing component to JavaScript.
Assignee: attinasi → rogerl
Component: Layout → JavaScript Engine
QA Contact: petersen → pschwartau
The reduced testcase above does not work in any browser: NN4.7, IE6, Mozilla. When you click on 'test2', you get an error in the JavaScript Console: Error: test2 is not a function Why? When you name an HTML element 'test2', that is registered by the DOM as a variable name in the document scope. That's why you can say things like |document.test2|. But function names are registered as variable names in the global scope, i.e. the window scope. So when you click on the button: <INPUT type=button value=test2 onclick="test2()"> the JavaScript Engine tries to look up |test2| and execute it. It does name lookup in local scope before trying global scope. So it finds |test2| as an HTML element, which is not a function, so you get the error. Have to mark this one invalid, but it's an interesting question -
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → INVALID
Marking Verified -
Status: RESOLVED → VERIFIED
cc'ing jst to make sure I invalidated this correctly - compare bug 57626.
Yup, INVALID. The HTML <INPUT type=checkbox name="test2">this checkbox name is test2 will make |test2| resolve to the above input element in the scope of the form where the input is (name="test2" is the key here).
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: