Fixing bug with added file in javascript