document.getElementById().innerText in Chrome
Asked Answered
G

1

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 ?

Geisler answered 10/10, 2011 at 14:21 Comment(1)
What does your markup look like?Junto
W
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?

Wallasey answered 10/10, 2011 at 14:23 Comment(2)
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.Barrel
Furthermore, using innerText on text boxes doesn't work in some browsers (Firefox, for example), so should be discouraged.Barrel

© 2022 - 2024 — McMap. All rights reserved.