views:

332

answers:

4

This works in Firefox, but not IE. Any help would be much appreciated! Thanks!

  var form = document.getElementById('theform')
    /* create the event handler */
    form.gen.onclick = function( evt ) {
        var f = evt.target.form
        var y = f.year.value
        var m = f.month.value
        genCalendar( document, y, m, 'theCalendar' )
    }
+1  A: 

As mentioned, IE does not pass the event object as a parameter. Try this:

var form = document.getElementById('theform')
  /* create the event handler */
  form.gen.onclick = function( evt ) {
    if(!evt)
      evt = window.event;
    var f = evt.target.form
    var y = f.year.value
    var m = f.month.value
    genCalendar( document, y, m, 'theCalendar' )
}

Or better yet, use a cross-browser library, like Prototype.js or jQuery.

gnud
also, you'll have to use `.srcElement` instead of `.target` in IE
Christoph
A: 

This is why you should consider using a javascript library such as jquery, YUI, or prototype. These libraries abstract away the browser based differences which simplifies your coding.

Glenn
+4  A: 

To get the target of an event in both standards compliant browsers and IE, use

var target = evt ? evt.target : window.event.srcElement;

There's an overview of the different properties of event objects at MDC.

Christoph
+1 for me, that solves the two main problems
SleepyCod
A: 
  • When does this script run? You might have to run this script onload, after the DOM is fully loaded
<script>

function go()
{
  alert('dom is loaded:  register event handlers now') ;
}

</script>

<body onload=" go(); ">



</body>

bobobobo