Closed
Bug 246197
Opened 19 years ago
Closed 15 years ago
js error when I click on image with onclick parameter
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
DUPLICATE
of bug 246385
People
(Reporter: pnovak, Unassigned)
Details
(Keywords: testcase)
Attachments
(1 file)
497 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a2) Gecko/20040603 Firefox/0.8.0+ Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a2) Gecko/20040603 Firefox/0.8.0+ HTML page: <form> <input type="text" name="myNumber" value="0"> <img src="images/something.gif" alt="+" width="20" height="20" border="1" onclick="myNumber.value = parseFloat(myNumber.value) + parseFloat(1)"> <button onclick="myNumber.value = parseFloat(myNumber.value) + parseFloat(1); return false">+</button> </form> When I click on the button myValue is increased. But when I click on img it gets into JS Console: "Error: myNumber is not defined". The same error when I use image map instead img. In Mozilla 1.6, Firefox 0.8, Konqueror 3.2 and IE 6 it's ok. Reproducible: Always Steps to Reproduce: Just try my example. Actual Results: JavaScript Error: "Error: myNumber is not defined" Expected Results: Increase value "myNumber"
you need to use document.getElementById("myNumber") and have <input type="text" id="myNumber" value="0"> your code does not follow the w3 way of doing things. this is not a bug.
(In reply to comment #1) > your code does not follow the w3 way of doing things. this is not a bug. maybe it did not validate before, but now JavaScript Console popups every time an error is found. i tried everything to disable it - no luck. i played around these settings, but nothing works - still popups on error. user_pref("javascript.console.open_on_error", false); user_pref("javascript.classic.error_alerts", false); user_pref("javascript.options.showInConsole", true); user_pref("javascript.options.strict", true); i think that console is a really powerful tool, but when it comes out every time i click on some buggy js it gets annoying. ff 0.9rc 20040609 build on windows
Sorry for flooding but looks like my problem is related to this bug http://bugzilla.mozilla.org/show_bug.cgi?id=213950 when a link has <a href="javascript:" url it opens a console.
Comment 5•19 years ago
|
||
No reply from reporter, marking as wfm Please reopen if you can reproduce this with a nighty build and a fresh profile
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → WORKSFORME
Reporter | ||
Comment 6•19 years ago
|
||
(In reply to comment #5) > Please reopen if you can reproduce this with a nighty build and a fresh profile Yes, I can reproduce this with Gecko/20041113.
Status: RESOLVED → UNCONFIRMED
Resolution: WORKSFORME → ---
Reporter | ||
Comment 7•19 years ago
|
||
Updated•19 years ago
|
Assignee: firefox → general
Component: General → DOM: Level 0
Keywords: testcase
OS: Linux → All
Product: Firefox → Browser
QA Contact: firefox.general → ian
Hardware: PC → All
Version: unspecified → Trunk
Comment 8•18 years ago
|
||
This bug is about the scope chain lookup for form controls. This bug 246197 is case 3 at this page: http://www.gtalbot.org/BugzillaSection/Bug253091.html If you had used document.forms[0].myNumber.value = parseFloat(myNumber.value) + parseFloat(1) it would work in *all modern browsers*. Even document.forms[0].elements["myNumber"].value = parseFloat(myNumber.value) + parseFloat(1) would also work in a wide majority of browsers. As mentioned by timeless, using an id and getElementById would also work. But the W3C allowed form controls to use the name attribute otherwise it would not be possible to send name and value pairs to the server. http://www.jibbering.com/faq/faq_notes/form_access.html#faInC So, there is definately a duplicate of this bug for sure... otherwise, I will reactivate bug 253091..
Whiteboard: DUP; chain scope lookup for form controls
Comment 9•18 years ago
|
||
Bug 246385 was (is) a duplicate of this bug: same basic description, same javascript console error message, same way to reference the button or form control, same statement that previous Mozilla release had not this problem.
Comment 10•15 years ago
|
||
In Internet Explorer, named form controls are visible in the global scope. This is wrong. If someone visits this bug, then (s)he can fix this problem by following timeless' recommendation in this bug's comment #1. More info available on how to do this at: Accessing Elements with the W3C DOM http://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM Resolving as a DUPLICATE of bug 246385
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago → 15 years ago
Resolution: --- → DUPLICATE
Whiteboard: DUP; chain scope lookup for form controls
You need to log in
before you can comment on or make changes to this bug.
Description
•