Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dynamically attach onchange script to checkboxes in catalog

Chris M3
Tera Guru

I'm wondering if this is possible.   I would like to detect a change to the value of any of a set of checkboxes, and run a script that validates what/how many are checked in order to determine whether the requirements for the form are meant.   I would like to be able to display that visually, rather then the user having to wait until an on-submit for the validation to occur/message to be displayed.

I would like this to be dynamic so that if there are 10 checkboxes, I don't have to write 10 seperate onChange client scripts.   I'm thinking one on-load script, with a list of the 10 checkboxes for it to loop through and attach a script or function to them.

8 REPLIES 8

Chris,



You can do it by actual element id, by using $("element id") to access that element.


I have a solution.   The visible checkbox did not have a change script, so I added an eventListenter to that.   I think I'll be able to get what I'm after.



Due to the risk with manipulating the DOM, I don't want to post my actual code, but the above should get people started if they want to pursue it.


Yeah that is what I am saying, you can observe an element for the events using id and do your manipulation accordingly. This link will be helpful


Prototype v1.7.3 API documentation | Event.observe


Hi Chris,



That's the way to go. Use Prototype as Abhinay has mentioned. I've done it a couple of times and it works like a charm.




Cheers



Greg