Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:40:03+00:00 2026-06-11T21:40:03+00:00

Suppose I add the event handler inline,use the onclick attribute of the element like

  • 0

Suppose I add the event handler inline,use the onclick attribute of the element like this:

<input type="button" value="Submit" onclick='buttonClick()' />

Then this is my handler:

<script type="text/javascript">
    window.buttonClick=function(e){
        e=e||window.event;
        alert(e.type);
        return false;
    }
</script>

Now I want to know how to get the event object? Since the above code will throw error:

e is undefined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:40:04+00:00Added an answer on June 11, 2026 at 9:40 pm

    That’s not using the event variable in the inline event.

    In this case buttonClick is a function called from the inline event; the called function does not have magical access to the event variable (window.event is an IE feature). Furthermore, in the post, buttonClick was called with 0 arguments so e will always evaluate to undefined.

    In any case, compare with the following which will work as access to the special event variable is done from the inline event itself and the event object is then passed off to the “real” event handler function:

    <input type="button" value="Submit"
           onclick="buttonClick(window.event||event)" />
    
    <script type="text/javascript">
        function buttonClick(e) {
            alert(e.type);
            return false;
        }
    </script>
    

    (I would recommend using jQuery or another library to make uniform event access easier, but that’s another story ..)


    Note that window.event||event is a dirty little trick:

    In IE window.event will evaluate to the event object and be be used as the result of the expression (so that event) is never evaluated. In non-IE browsers, window.event will evaluate to undefined (unless someone is doing some really bad things) and thus the result will be that of the event variable.

    Reversing this to event||window.event would cause a ReferenceError in browsers (i.e. IE) that do not support the W3C local event variable approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is suppose to add an onClick event to each of the a
Let's suppose there is an <img> element that has some onclick event handler. For
Let's suppose I have such handler: ed.onNodeChange.add(function(ed, cm, e) { }); How to get
Suppose I want to add two buffers and store the result. Both buffers are
Suppose you want to dynamically add to a HTML menu, where the menu HTML
Suppose I have a Python class that I want to add an extra property
This is a classic sort of question, I suppose, but it seems that most
I have a design questions about this scenario: Suppose you have a form with
I have a DataGridView and a handler for the EditingControlShowing event which is used
I want to implement that when a textbox value is changed, my Add button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.