fixed undefined variable in javascript