addEventListener not working in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 11:21 AM
Hi everyone,
I'm working with a catalog item and trying to perform a calculation whenever a user types into a single-line text box variable. Here's what I did:
var s = g_form.getControl("variable_name");
s.addEventListener('keyup', functionName);
function functionName() {
alert('inside function');
}This works perfectly in the Catalog Item (Try It) view.
However, when I try the same in the Service Portal, it throws an error:
TypeError: s.addEventListener is not a function.
I understand that onChange only triggers when the field loses focus or when the user clicks elsewhere, which is why I used addEventListener to detect keystrokes directly.
Does anyone know why this approach works in the regular catalog view but not in the Service Portal? Or is there a recommended way to handle keyup or live input tracking in the Service Portal?
Thanks in advance for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
The issue you're having is because in catalog client script .addEventListener is not a function. Therefore, most likely in your front view console you will see a log stating:
Events.js:100 wrong listener type: undefined
Tested on my end, set the script within a catalog client script. In order to get the actual DOM element, you'd need to modify your widget DOM entrance in Portal.
