I saw many examples and did the same but I cannot set value with JavaScript.
There is my code
<h:form id="listPlacesForm">
<h:inputHidden id="hiddenMapCenter" value="#{userPlaces.center}" />
</h:form>
and JavaScript
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(findPosition);
} else
error('Geo Location is not supported');
function findPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
alert('Start')
var str = lat + ", " + lng;
var elem = document.getElementById('listPlacesForm:hiddenMapCenter')
alert(str)
elem.value = 'asfsf'
alert('It works!' + str);
}
All these code works except line: elem.value = 'asfsf'
I tried: elem.value = 'sfd'
, elem.value = "asfd"
, elem.value = str
Any ideas?
UPDATE 1
Generated HTML
<form id="mainTabId:listPlacesForm"
name="mainTabId:listPlacesForm" method="post"
action="/DarkComm/app/settings?execution=e3s1" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="mainTabId:listPlacesForm" value="mainTabId:listPlacesForm" />
<input id="mainTabId:listPlacesForm:hiddenMapCenter"
type="hidden"
name="mainTabId:listPlacesForm:hiddenMapCenter" value="" />
<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="e3s1" />
</form>