Different Results even Code is Same

Different Results even Code is Same

Hello
I am trying to copy selected values from One dropdown to another.
I have total sixdropdown , three dropdown for Country,State and City and another three for  Country ,State and City .

i want to Copy Country to Country , State to Stateand City to  City .


If i execute code over console it gives fine.but if write same code to file and  try to execute using function 
It gives only country 
what to do  ?