Javascript set value of an input field
53,032
Solution 1
So using the following method for setting attributes worked fine.
document.getElementById("geofeld").setAttribute("value", geo_poi);
Solution 2
For situations when setAttribute does not yield any result (think HTML5 user/password input), consider this:
document.getElementById("geofeld").setRangeText("text");
Author by
redestructa
Updated on July 31, 2022Comments
-
redestructa almost 2 years
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.
-
engineerX over 9 yearsThis does not look like "Javascript" to me. You might be using some library.
-
shieldgenerator7 about 8 years@engineerX Probably jQuery
-
Võ Minh over 5 yearsso this is javascript right? <input type="text" onchange="passvalue()" placeholder="Item 1" id="item1" /> <input type="text" placeholder="Item 2" id="item2" /> <script> function passvalue() { var pValue = document.getElementById('item1').value; document.getElementById('item2').value = pValue; } </script>