5

Quick Cross Browser JS question, when setting the value of a textbox:

document.getElementById("balanceText").innerText = "111";

and

document.getElementById("balanceText").value = "111";

Both Work grand in IE,

But they will not work in Chrome, FF, Opera or Safari.

Is there an alternate method that will work in these browsers ?

strvanica
  • 197
  • 3
  • 6
  • 14

1 Answers1

14

All else being equal document.getElementById("balanceText").value = "111"; works fine in every significant* browser that supports JS.

Make sure that you have one, and only one, element with id="balanceText" and that it actually has that as its id and not just the name.

* you don't care about NS 4 do you?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    Fwiw (not much), the `value` property works fine in NS 4 (and indeed NS 3 and NS 2). It's just the `document.getElementById` bit that doesn't. – Tim Down Oct 10 '11 at 14:42
  • Furthermore, using `innerText` on text boxes doesn't work in some browsers (Firefox, for example), so should be discouraged. – Tim Down Oct 10 '11 at 14:44