On 4/22/07, Jorge Godoy <[EMAIL PROTECTED]> wrote:
> "troels knak-nielsen" <[EMAIL PROTECTED]> writes:
>
> > could simply do signal(element, "onchange")?
>
> I may be missing something, but I do "signal(element, 'onchange')" today
> with MK and it works.  Tested on FF 1.5, 2.0, IE 6 and IE 7.

It doesn't trigger events assigned inline or directly. Here's a demonstration:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
<html>
<head>
  <title>fireNativeEvent test</title>
  <script src="MochiKit.js" type="text/javascript"></script>
<script type="text/javascript">
/**
  * Fires a native HTMLEvent on an HTMLElement
  * element : HTMLElement  The target element
  * eventName : string     The name of the event to raise. Should be
all lowercase and include the trailing 'on'.
  */
fireNativeEvent = function(element, eventName) {
  if (element.fireEvent) {
    // MSIE
    element.fireEvent(eventName);
  } else {
    // W3C
    var event = document.createEvent("HTMLEvents");
    event.initEvent(eventName.replace(/^on/, ""), true, true);
    element.dispatchEvent(event);
  }
}
var isSetup = false;
runTest = function(mode) {
  if (!isSetup) {
    connect($("foo"), "onchange", function() {
      output("connected-event");
    });
    $("bar").onchange = function() {
      output("directly-assigned");
    }
    isSetup = true;
  }
  output("<br/>running test for: " + mode);
  if (mode == 'native') {
    fireNativeEvent($("foo"), "onchange");
    fireNativeEvent($("bar"), "onchange");
  } else if (mode == 'signal') {
    signal($("foo"), "onchange");
    signal($("bar"), "onchange");
  }
}
output = function(msg) {
  $("debug-output").innerHTML += "<br/"+">" + msg;
}
</script>

</head>
<body>

<input name="foo" id="foo" value="" onchange="output('inline-event')"
type="text" />
<input name="bar" id="bar" value="" onchange="alert('error: should be
re-assigned by setup')" type="text" />

<div>
  <input type="button" value="run test: native" onclick="runTest('native')" />
  <input type="button" value="run test: signal" onclick="runTest('signal')" />
</div>

<div id="debug-output" style="padding:1em;background:#eee">
</div>


</body>
</html>

-- 
troels

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to