0

Hello I'm using following code for checkbox to close some type of time picker, the code works fine in chrome but not works in Mozilla Firefox. While running on Mozilla Firefox we got the following error, please suggest me some alternative so that it works in both browsers.

Error: closeMonday is not defined

and the code is:

<div class="checkbox" name="closeMonday" style="height:16px;float:left;margin-left:0;margin-top:0;margin-right:5px;display:block" onclick="onClickChangeValue(closeMonday.checked);">
asked Jul 26, 2011 at 7:46

1 Answer 1

3

Simply change the onclick to:

onclick="onClickChangeValue(this.checked);"

The word this is reserved in JavaScript to describe the "current" element for example in click events, the element being clicked, so this is what you should use.

Chrome is probably "smart" enough to search the document for real element with such name or ID but you should not count on such behavior.

answered Jul 26, 2011 at 7:48
Sign up to request clarification or add additional context in comments.

5 Comments

be notes that this object reffer to a div so the div is not a checkbox
@Marwan - I guess he's using custom attributes which is fine. Raman - I'm glad it's working. :)
@Shadow Wizard - no no I'm thanking to you, its your code which helps me to work. thanks once again.
Cheers, in such case feel free to Accept the answer as correct by ticking the V icon to the left. :)
Chrome installs the global scope polluter (the thing that makes window.closeMonday be that <div> element) on all pages. Firefox only does that in quirks mode.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.