Improved javascript for field detection.