Set Javascript value of input field

Since I cannot set the value of an input field with type = text. I used to always use 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; 

It always worked. Perhaps new browsers no longer want to support the above method.

+6
source share
3 answers

Thus, using the following method for setting attributes worked fine.

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

In situations where setAttribute fails (consider entering an HTML5 user password), consider the following:

 document.getElementById("geofeld").setRangeText("text"); 
+1
source

HTML


 <input type="text" placeholder="Item 1" id="item1" /> <input type="text" placeholder="Item 2" id="item2" /> 


JAVASCRIPT


 $('#item1').blur(function() { var item1var = $('#item1').val(); $('#item2').val(item1var); }); 

Jsfiddle HERE

-1
source

All Articles