Detect checkbox clicked

brycefraser
Giga Contributor

Hey all

I have a catalogue form with a large list of checkboxes.

I'd like to know how to detect which checkbox has been clicked by a requestor so I can apply a style to differentiate it from the checkboxes that are auto-filled.

I've no idea where to start.


Anyone got any ideas?

Thanks!

1 ACCEPTED SOLUTION

Hi Bryce, you were right! Here goes the fix. Add the following at the beginning of your inline defined onclick function (@ line 12)



gel('IO:' + item.sys_id).value = this.checked;if (typeof(variableOnChange) == 'function') variableOnChange('IO:' + item.sys_id);




I'll appreciate if you can mark this post as the correct one or as a helpful one so that others reading this post in the future know that this line is *key* to be added in the inline defined onclick function.




Thanks,


Berny


View solution in original post

23 REPLIES 23

Berny,



Still can't seem to get it to work.



I commented out everything in the function except these lines:


gel('IO:' + item_sysid).value = this.checked;


if (typeof(variableOnChange) == 'function') variableOnChange('IO:' + item_sysid);




Still doesn't bring the checkboxes across to the catalogue item.



I'm going to have to table this issue for now and come back to it if I get time at the end of this project.



Thanks again for all your help with this, I've definitely learned a lot!


This is awesome! Thank you guys but how could I do the same with a checkbox at the bottom of the related list for Approvers specifically the "Select All" check box which is a UI field that is generated when the page is loaded and always has a different label made up of "allcheck_"+NewSysID (my slang but it is a new one everytime.) any help would be hugely appreciated.


find_real_file.png


Hi Jimmy, that checkbox you're referring to it's different from the one referred on this post. Listening to a click on that checkbox may be possible with quite a hack solution using UI scripts. The solution though will nor reliable nor scalable since it will rely on DOM elements within the ServiceNow platform that are likely to change in newer version/releases.



My advice will be to actually work within the UI actions which are triggered based on the user selection. You can customize these to do something at the beginning of the script which could be on most use cases equivalent to listening to the click event of the checkbox.



I hope this helps



Thanks,


Berny


I have my check boxes set up correctly, but the problem is when the end user goes in to portal to complete the service request after its submitted the items selected by requester do not display in fulfillment catalog task view. Do you have the script or workaround solution for this? All of the checkbox items display, but it doesn't indicate which items were actually selected by the person submitting the request.