Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with attachEvent 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
0
0
US
I'm trying to set an event handler and avoid using the event parameter in my input tags. I'll be addressing the cross-browser issue with this function but I hit a wall implementing the IE code.

I have this strategy in use for another event where the function does not need a parameter and it works great, such as: oInputs.attachEvent('onkeyup',formhasChanged);

However when I need to pass a value to my event function I get an "object required" error when the function calls the input/textarea object on the line "var y=document.getElementById(elem).value;". The object reference elem is apparently not an object.

Any ideas on how to accomplish this?
Thanks
Code:
<body onload="setonkeyupEvent();">

function setonkeyupEvent(){
 var oInputs = document.getElementsByTagName('textarea');
 for (var i = 0; i < oInputs.length; i++){ oInputs[i].attachEvent('onkeyup',function(){upperCase(this.id)})
  }
}

function upperCase(elem){
 var y=document.getElementById(elem).value;
 document.getElementById(elem).value=y.toUpperCase();
}




Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
[tt]
for (var i = 0; i < oInputs.length; i++){
[red]//[/red]oInputs.attachEvent('onkeyup',function(){upperCase(this.id)});
if (window.attachEvent) {
oInputs.attachEvent('onkeyup',function(event){upperCase(window.event.srcElement.id)});
} else if (window.addEventListener) {
oInputs.addEventListener('keyup',function(event) {upperCase(event.target.id)},true);
}
}[/tt]
 
Thanks tsuji!!!

Shouldn't addEventListener('[red]keyup[/red]'...
be addEventListener('[red]onkeyup[/red]'...?



Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
No,... each camp is free to innovate!
 
What about onchange? Do you know of a link that lists the events for reference?

Thanks agian tsuji

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
It would be the same prefix construction rule, change versus onchange, click versus onclick etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top