Repaired javascript code to work correctly.