Added condition on javascript to avoid infinite loop