onChange for UI Page

kyrresc
Tera Expert

Hello,

I have a UI Page with a g:ui-date jelly-tag. Is it possible to have an onChange function on this field? So that when you change the date, the function is called.

1 ACCEPTED SOLUTION

https://community.servicenow.com/community?id=community_question&sys_id=2c0fcba1dbdcdbc01dcaf3231f9619ae

 

This worked!

View solution in original post

8 REPLIES 8

Willem
Giga Sage
Giga Sage

Not sure. Have you tried adding onchange="myFunction()" to your g:ui-date jelly-tag?

 

You could try add an event listener if your g:ui-date jelly-tag has an ID tag for example:

document.getElementById("your_id").addEventListener("change", onChangeFunction);

function onChangeFunction() {
  //do what you want to do onChange
}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

onChange atttribute won't work for <g:ui_date> tag

You can perform validation during submission.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

kyrresc
Tera Expert

Thanks, both. Where would you call the eventListener? @Willem 

 

Is there a work-around for this? Can I pass the variable from the <g:ui_date> tag to a HTML tag (hidden input field?) which has an onChange attribute?

the event listener is client script, so you can put it in the Client script field on the UI Page.

 

But since it is a Jelly tag, I am not sure it will work. If you are able to pass it to a hidden input field, then both options ( "onchange=" and event listener) will definitely work for a regular input field.