E_Spencer Posted December 16, 2008 Share Posted December 16, 2008 I have the below code. I am trying to add the function chgDI() as the handler for onChange event. However, the reference chgDI(newelement.value), if in parentheses, is not recognized as a function call. If parentheses are left out, it is called only when the drawBOX function is called, and not when the text area changes. Using addEvent results in a 'mismatch' error. Using setAttribute doesn't work either. What can I do?CODE within drawBOX() function: newelement.attachEvent("change", chgDI(newelement.value)); -OR-newelement.setAttribute("onChange" , "chgDI(newelement.value)"); I've tried both statements with and without parentheses. I've tried change and onchange in the attachEvent parameters. No joy.I'm using Frontpage 2003, and veiwing in IE7 Link to comment Share on other sites More sharing options...
aspnetguy Posted December 16, 2008 Share Posted December 16, 2008 newelement.attachEvent("change", function() { chgDI(newelement.value); }); Link to comment Share on other sites More sharing options...
Ingolme Posted December 16, 2008 Share Posted December 16, 2008 I have the below code. I am trying to add the function chgDI() as the handler for onChange event. However, the reference chgDI(newelement.value), if in parentheses, is not recognized as a function call. If parentheses are left out, it is called only when the drawBOX function is called, and not when the text area changes. Using addEvent results in a 'mismatch' error. Using setAttribute doesn't work either. What can I do?CODE within drawBOX() function:newelement.attachEvent("change", chgDI(newelement.value)); -OR-newelement.setAttribute("onChange" , "chgDI(newelement.value)"); I've tried both statements with and without parentheses. I've tried change and onchange in the attachEvent parameters. No joy.I'm using Frontpage 2003, and veiwing in IE7 attachEvent, unlike addEventListener requires you to put the "on" in the event type.attachEvent("onchange", function() { chgDI(newelement.value); })Just so that you know, attachEvent is an Internet Explorer exclusive function. For standard browsers use addEventListener. Link to comment Share on other sites More sharing options...
E_Spencer Posted December 19, 2008 Author Share Posted December 19, 2008 Thanks, that worked like a charm. I was going to ask, but the next post states that this is an IE exclusive statement.Does addEventListener work on IE? If so, why not use it instead? Or do I need to have the page determine which browser is being used, and call the appropriate function?Thanks newelement.attachEvent("change", function() { chgDI(newelement.value); }); Link to comment Share on other sites More sharing options...
Ingolme Posted December 19, 2008 Share Posted December 19, 2008 attachEvent won't work in standard browsers, and addEventListener won't work in Internet Explorer, so you'll have to test to see if it works first, like this: if(document.addEventListener) { myElement.addEventListener(... ... ...);} else if(document.attachEvent) { myElement.attachEvent(... ... ...);} else { myElement.[onclick, onload, onchange... ]} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.