Completed JavaScript for Survey