Finished javascript for new/edit instances