JavaScript registration function working-ish