You Can't Change a <input type="checkbox" If You're IE?
Update November 20th: Well, a quick search of StackOverflow.com, and it turns out that I’m not exactly alone in this matter. According to this post (and Grant in the comments of this post), in versions of IE < 8, one must use the click event, and not the change event.
I ran into an interesting issue today. I don't really know the answer, but I figured I would blog about it so that I don't completely forget it. While I highly doubt the two readers of my blog (my brother and sister) have any idea of what I'm talking about, I'm sure that eventually somebody (smart) will stumble upon this via Google. What will happen in that case is anybodies guess, but I digress...
I had some JavaScript (note that I'm using jQuery too):
1: $(document).ready(function() {
2: $('#myCheckbox').change(myCallBackFunction);
3: }
4:
5: function myCallBackFunction() {
6: // unwrap protein strings and cure cancer in parallel on a single core system
7: }
For the sake of completeness, here is a sample HTML snippet to go with the above jQuery:
<input id="myCheckBox" type="checkbox" >
Now, in FireFox 3, when you clicked on the checkbox, myCallBackFunction gets executed (as I would expect). However, in IE7, that doesn't seem to happen. This has me stumped.
Now, at work, I asked "Who is an expert in Javascript and jQuery?". Crickets chirped. Dead silence. A tumbleweed rolls on by.
I then asked "Who wants to make Tom look stupid?" - everybody jumps at the opportunity. Go figure. Anyway, back to our exciting tale. To get around this, I couldn't rely on the collective brainpower of myself and my co-workers to figure out what the problem is. Instead, we deduced that it is better to go around the problem and try something different. I had to use the click event like so:
$('#myCheckbox').click(myCallBackFunction);
This works in both IE7 and FireFox 3 - not sure why.
Based on my past experiences with things, I'm sure it's something I'm doing (or not doing). Going over my past experience, I'm sure it won't be me who figures out what I'm doing wrong.