Drop downs autofill on subforms question

Drop downs autofill on subforms question

I have a script on a form called billing form that autofills information from a Form called Add Kids Form and Add Parents Form I understand this does not work on subforms because of some issues and I've read up on it, but I still don't understand how to implement it on a subform. Can you please help me rewrite the code below so it would work on a subform? And please tell me where to place the code. Thank you.

the script is:

  1. if((input.Select_Child  !=  null))
  2. {
  3.     rec = Add_Kids_Form[ID == input.Select_Child];
  4.     //fetching that particular record into a User defined variable rec
  5.     Daily_Rate=rec.kid_rate;
  6.     //assigning corresponding values
  7.     parentrec=rec.Parent_Name;
  8.     newparentrec = Add_Parents_Form[ID == parentrec];
  9.     Copay=newparentrec.dhs_copay;
  10. }