J wrote:
> The method you suggested is correct, but still doesn't solve my
Please don't top post, reply below trimmed quotes.
> problem. If I put the following lines to attach the two events:
>
> inp.attachEvent('onchange',
> function(event){nameclick(strand);});
> inp.attachEvent('onkeyup',
> function(event){namechange(strand);});
>
> Only the onkeyup event is active (If I put the "onchange" event
> second, it will be active.) I can't get both to be active at the same
> time using these calls for IE6. Again, mozilla works fine with the
> same code. It's as though the IE model only has room to attach one
> event. Anyone else seen this issue?
Remove the "IE specific" code completely, it does nothing useful. Use
attachEvent and addEventListener only if you want to add multiple
handlers for the same event. It is much more reliable to use your "non
IE" method:
element.eventName = functionName /or/ functionExpression;
Your issue is likely in regard to a conflict between onchange and
onkeyup. The following example may help - note that in IE you need to
click outside the input to make the onchange handler fire, whereas in
Firefox, the onchange alert causes the input to lose focus and hence
onchange to fire.
<script type="text/javascript">
// Single handler method
function addEvent0(el, evt, fn){
el['on'+evt] = fn;
}
// Multiple handler method
function addEvent1(el, evt, fn, capture){
if (el.addEventListener){
el.addEventListener(evt, fn, capture);
} else if (el.attachEvent){
el.attachEvent('on'+evt, fn);
}
}
function nameClick(){alert('nameClick');}
function nameChange(){alert('nameChange');}
</script>
<input type="text" id="inp0">
<input type="button" value="addEvent0" onclick="
var el = document.getElementById('inp0');
addEvent0(el, 'keyup', nameClick);
addEvent0(el, 'change', nameChange);
">
<input type="button" value="addEvent1" onclick="
var el = document.getElementById('inp0');
addEvent1(el, 'keyup', nameClick, false);
addEvent1(el, 'change', nameChange, false);
">
--
Rob
|