Filter child table based on parent value?

How can I filter a child field base on parent field in javascript?

use case:

I have a parent field item_parent and when I click to add a new row in the child table there is an item code which should be filtered base on the item_parent selected in the parent field.

any idea how to do this?