Change javascript function, make query to get question data from question table, add if to remove undefined-offset error