-1

I'm trying to change the value of a button from 'send' to 'sending' when it's clicked.

I get the error above called on this line:

document.getElementById("submin_btn").setAttribute("value","Sending...");

What's the problem?

Robert Kerr
  • 1,291
  • 2
  • 17
  • 34
DBWeinstein
  • 8,605
  • 31
  • 73
  • 118

1 Answers1

0

getElementById returns null if it can't find an element with the supplied ID. A more robust method (i.e. one that wont throw errors) is:

var button = document.getElementById("submit_btn"); // spelling of "submin_btn"?
if (button) button.value = "Sending...";

However, if the button is in a form, likely you will not see the value change in some if not most browsers. When a form submits (or navigation away from the current page begins) they cease updating the visible DOM (likely they figure "what's the point?").

RobG
  • 142,382
  • 31
  • 172
  • 209