RE: Auto populate account for Selected contact
Hi Saman,
you can create a workflow to achieve it, which is a no code way and easier than js.
You can refer following steps.
1.Go Settings > Process to create a Real Time workflow on opportunity entity

2.Trigger it on Create and contact field change.
If you want to fill account from contact automatically for existing opportunities, you can check 'As an on-demand process'

3.Update the value of account from contact.

4.Save and Active it.

5.Test.
Fill contact field and save it, the account field will be filled automatically.

Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.