Populate child table field on changing another child table field


I’ve a doctype where I’ve two child tables. How can I populate the 2nd child table field when I change 1st child table field.

Consider last 2 child tables namely ITEMS TAKEN and ITEMS RETURNED. Now as soon as I enter ItemCode in ITEMS TAKEN child table of this doctype, the same should be reflected in ItemCode of ITEMS RETURNED child table. Though this is not the exact requirement, I need to know how to achieve that functionality using custom script.
(FYI: The actual requirement is exactly same but with the first table in the screenshot and another new child table which is yet to be added.)

Any help is greatly appreciated. Thanks.