Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript set value of an input field

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.

like image 276
redestructa Avatar asked Apr 19 '13 09:04

redestructa


2 Answers

For situations when setAttribute does not yield any result (think HTML5 user/password input), consider this:

document.getElementById("geofeld").setRangeText("text");
like image 192
David Salamon Avatar answered Oct 28 '22 14:10

David Salamon


So using the following method for setting attributes worked fine.

document.getElementById("geofeld").setAttribute("value", geo_poi);
like image 34
redestructa Avatar answered Oct 28 '22 16:10

redestructa