Custom script to Filter Options in select field

Hello guys.
I want to filter options in City based on State selected.
I have tried to understand how Options are filtered In select field using custom script from erpnext documentation but I’m not getting get right . please I need more explanation on how to implement it.