Loading ...
Sorry, an error occurred while loading the content.

Re: Problem!

Expand Messages
  • Lucas Smith
    ... src= http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js ... IE uses o.srcElement rather than o.target. You can use var
    Message 1 of 2 , Sep 30, 2008
    View Source
    • 0 Attachment
      --- In ydn-javascript@yahoogroups.com, "faka3o" <faka3o@...> wrote:
      >
      > anybody knows why the following code doesn't work in Internet Explorer?
      >
      > I get the following error when I click the checkboxes:
      > 'target.id' is Null or not an Object
      >
      > but it works fine in Firefox and Opera
      >
      >
      >
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      > "http://www.w3.org/TR/html4/strict.dtd">
      > <html>
      > <head>
      > <meta http-equiv="content-type" content="text/html; charset=utf-8">
      > <title>Simple Event Handling and Processing</title>
      > <link rel="stylesheet" type="text/css"
      > href="http://yui.yahooapis.com/2.5.2/build/fonts/fonts-min.css" />
      > <script type="text/javascript"
      >
      src="http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
      > </head>
      >
      > <body class=" yui-skin-sam">
      > <input type="checkbox" id="mid_1" /> Checkbox 1 <br />
      > <input type="checkbox" id="mid_2" /> Checkbox 1
      > <script language="javascript">
      > function whichCheckbox(o){
      > var id = o.target.id.substring(4);
      > alert(id);
      > }
      > YAHOO.util.Event.addListener("mid_1", "click", whichCheckbox);
      > YAHOO.util.Event.addListener("mid_2", "click", whichCheckbox);
      > </script>
      >
      > </body>
      > </html>
      >

      IE uses o.srcElement rather than o.target. You can use var target =
      YAHOO.util.Event.getTarget(o); to get the target, then refer to target.id.

      Hope this helps,
      Luke
    Your message has been successfully submitted and would be delivered to recipients shortly.