Question

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?

Was it helpful?

Solution

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?").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top