Categories | Question details Back To List | ||
event object passed to the event handler I've used the following code to create a combo <select name="primaryStateProvinceCd" onchange="updateAddress(event);isCanadian();onPrimaryAddressChange ()" id="primaryStateProvinceCd"> <option value=""></option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> </select> <script> var primaryStateProvinceCdCombo=dhtmlXComboFromSelect("primaryStateProvinceCd", 214); primaryStateProvinceCdCombo.enableFilteringMode(true); primaryStateProvinceCdCombo.enableFilteringOnValue(true); primaryStateProvinceCdCombo.attachEvent("onBlur", function(){ var comboText=this.getComboText(); var selectText=this.getSelectedText(); if (comboText != selectText) { this.setComboText(selectText); } }); </script> When I get into the updateAddress function, the event object is undefined. I've also tried removing the onchange in the select and adding the event with the following attachEvent call with the same results. primaryStateProvinceCdCombo.attachEvent("onChange", function(event){ updateAddress(event); isCanadian(); onPrimaryAddressChange () }); In Firebug, I have a breakpoint on the call to updateAddress and event is undefined. How do I get a reference to the event object? Answer posted by Support on Feb 12, 2008 10:09 Event object is not accessible from onBlur event of combo - actually onBlur event of combo is not equal to normal html onBlur - because combobox consists from few elements. Why do you need a native event object in first place ? Answer posted by Steve Compton on Feb 12, 2008 10:25 It's the on change event that I need the event object for. The page has 4 addresses. A change to one address can trigger the change to be copied to the corresponding field in another address. The call to updateAddress(event) is in the onchange for every address form field. In the beginning of updateAddress, we use the event object to determine what field changed. function updateAddress (e) { if (navigator.appName.indexOf("Microsoft") != -1) { e = window.event; element = event.srcElement; } else { element = e.target; } var elementName = element.name; I've inherited this code, so I'm currently looking at changing the calls to pass this instead of event, but I haven't fully investigated the impact. I was just curious about how to get the event object. Answer posted by Support on Feb 13, 2008 03:40 There are many ways how onChange event can be called in combo, and while it not so complex - there are many updates in code necessary to transfer real event to the custom onChange event. If you need to have a var elementName = element.name; you can have it as combo.attachEvent("onChange",function(){ var elementName = this.name; ... }); |