Consider the following example (also available here: http://jsfiddle.net/hq8Fg/1/). It works fine in IE9, but doesn’t work in Chrome 16.
In IE, if I click on the radio button, I see the message, but in Chrome nothing happens.
<!DOCTYPE html>
<html>
<head>
<title>Nothing</title>
<script type="text/javascript">
function begin() {
var rb1 = document.getElementById('rb1');
rb1.addEventListener('focus', function() { document.getElementById("theText").value = "focus"; }, false);
}
</script>
</head>
<body onload="begin()">
<input id="rb1" type="radio" />
<textarea id="theText"></textarea>
</body>
</html>
Any idea why it’s not working in Chrome and what I can do to fix it?
p.s. I know I can probably use a library like JQuery, but I want to know if it’s possible without using any libraries.
You could try the
onclickevent since the problem isn’t that the event is not called when the element gets focused; The problem is that it is really not focused on click. You can figure that out through focusing your textarea and then pressing SHIFT+Tab.