简体   繁体   中英

How to access Event object inside javascript tag of Aspx page header content?

I am trying to fire a event from script inside aspx page. To fire a event I am using Event.observe() method. In that line I am getting error like "Event is not an object". Please help me in this issue.

My code:

 function Submitkeyword() {
        obj = document.getElementById("select");//select is button id
        Event.observe(obj, 'change', function () {
            var e = document.getElementById("lookupvaluesDropdown");//lookupvaluesDropdown is dropdownlist id
            var valueddl = e.options[e.selectedIndex].value;                
        });
        fireEvent(obj, 'submit'); 
        window.close(); //To close the popup window
    }
    function fireEvent(element, event) {
        if (document.createEventObject) {
            // dispatch for IE
            var evt = document.createEventObject();                 
            return element.fireEvent(event, evt);
        }
        else {
            // dispatch for firefox + others 
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent(event, true, true); // event type,bubbling,cancelable 
            return !element.dispatchEvent(evt);
        }
    } 

Event.observe requires the Prototype JavaScript library loaded. If its not loaded and you try to use it you will get the error "Event is not an object"

You need to include that in your <head> as follows :

<script src="/path/prototype.js" type="text/javascript"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM