Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

onChange for multi line text fields

shart
Kilo Explorer

I am having an issue with the onChange script running on a multi line text field, it seems to fire onLoad but not if I change the content of the field and tab out? The specific script is running against work around on the problem.

1 REPLY 1

Mark Stanger
Giga Sage

Textarea fields work a little bit differently than regular text fields. The way that it should work is to have the onChange event fire when the focus leaves the field. As it is, Service-now doesn't even attach an onChange event to textarea fields. You can attach your own event to a textarea field though using client scripting. I have done this before and added an 'onKeyUp' event (which fires each time you press and release a key) to mimic an 'onChange' event. You should be able to set the onchange event (which should fire when the field loses focus) this way as well. Here's a sample script. It should be set up as an 'onLoad' client script so that it can attach the event to the textarea element.



function onLoad() {
//Attach a custom event to the 'comments' textarea element
//Get the control
var control = g_form.getControl('comments');
//Set its onkeyup method
control.onkeyup = myCustomFunction;
}

function myCustomFunction(){
//Do regular client script stuff for your custom event here
}