updated javascript to handle result.