Event not supported in Mozilla

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SwapnilD
    New Member
    • Jan 2010
    • 41

    Event not supported in Mozilla

    I have following code to generate a transpert pop up for onchange event of drop down

    Code:
    if (xmlHttp.readyState==4)
    { 
    	/* get the mouse left position */
    	var x = [B]event[/B].clientX + document.body.scrollTop + 360; // LINE 1
    	/* get the mouse top position */
    	var y = [B]event[/B].clientY + document.body.scrollTop + 330; // LINE 2
    	/* display the pop-up */
    	
    	/* set the pop-up's left */
    	Popup.style.left = x;
    	/* set the pop-up's top */
    	Popup.style.top = y;
    	Popup.style.display="block"; 
    	document.getElementById("Popup").innerHTML=xmlHttp.responseText;
    Above code works fine for IE but in MOzilla it gives error "EVENT is not defined"
    Please note: LINE 1 and LINE 2 are used to adjust position of window. If I remove it code works fine for all browsers but does not have a position that I want.

    Please help
    Last edited by Dormilich; Jan 12 '10, 02:56 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    correct, Mozilla does not have a global event attribute (window.event) like IE. you need a parameter in the function call (which is auto-populated by JavaScript) to access the event object.

    Originally posted by MDC
    Event handlers may be attached to various elements in the DOM. When an event occurs, an event object is dynamically created, and passed sequentially to the event listeners that are allowed to handle the event. The DOM Event interface is then accessible within the handler function, via the event object passed as the first (and the only) argument.
    see also clientX and event @ MDC

    Comment

    • SwapnilD
      New Member
      • Jan 2010
      • 41

      #3
      How can I do that. Can you please give an example?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        check out the given links, they contain plenty of examples.

        Comment

        • SwapnilD
          New Member
          • Jan 2010
          • 41

          #5
          Per your suggestion I have changed the function as below

          "function stateChanged2(e vent) " // I have passed Event attribute

          It works fine for Mozilla but does not work for IE i.e. Exactly the revere case of above.

          How can I deal with this.

          I really appreciate your prompt responses.

          Thanks.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I’m not familiar with IE issues, but you shouldn’t name the variable "event" (same goes for any reserved keyword). I guess that IE does not pass this parameter, so it overwrites the global attribute event due to the parameter having the same name.

            but of course you can test for either version:
            Code:
            function handle(evt)
            {
                var evt = evt || window.event;
                evt.clientX = …
            }
            How can I deal with this.
            discard IE ;)

            Comment

            • SwapnilD
              New Member
              • Jan 2010
              • 41

              #7
              Thanks buddy...I have modified the code as below and it is working fine for all the browsers (IE, FF, CHROME and SAFARI)

              Code:
              function stateChanged2(evt) 
              { 
              if (xmlHttp.readyState==4)
              { 
              	var evt = window.event || evt;
              You are really GREAAATTTTTT... ...!
              Last edited by Dormilich; Jan 12 '10, 03:28 PM. Reason: Please use [code] tags when posting code

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                please don’t exaggerate, I’m not that great, this is just common cross-browser knowledge.

                Comment

                • RedSon
                  Recognized Expert Expert
                  • Jan 2007
                  • 4980

                  #9
                  We <3 Dormi

                  Comment

                  Working...