Javascript set value of an input field

redestructa picture redestructa · Apr 19, 2013 · Viewed 50.1k times · Source

Since while I cannot set the value of an input field with type=text. Before, I always used something like this:

<input style="display: none" type="text" name="geo_poi" value="" id="geofeld" />

Then, in JavaScript i added code containing a line like this:

document.getElementById("geofeld").value = geo_poi;

This always worked. Maybe the new browsers don't want to support the method above anymore.

Answer

redestructa picture redestructa · Apr 19, 2013

So using the following method for setting attributes worked fine.

document.getElementById("geofeld").setAttribute("value", geo_poi);