Hi Rashmi
I see two parts to your issue
JavaScript on the signup form to populate one drop down based on the other
I can barely help you here , I have done the exact same thing but I have injected jquery in my signup.php to do this rather than use moodles recommended JavaScript guidelines
The other thing ,you can use event observers to observer user_created
Read https://docs.moodle.org/dev/Event_2 event observers
Reading your requirements I would suggest you set up external enrollment and use that to enroll the users in the particular course , hope this is useful