Updated JavaScript to work with HTML form.