Вопрос

i have two inputtext which i want to prepopulate with geolocation data that is city and country. This is api i want to use to get location

      <script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>

  <script language="Javascript"> 
    document.write(geoplugin_city(), geoplugin_countryName()); 
  </script>

JSF:

<h:inputText id="city" style="width:100%;"  value="#{m.city}"></h:inputText>

<h:inputText id="city" style="width:100%;"  value="#{m.country}"></h:inputText>
Это было полезно?

Решение

First : you gave same id to your inputText change the second one to country

Try something like this

document.getElementById("yourFormId:city").value = geoplugin_city();
document.getElementById("yourFormId:country").value = geoplugin_countryName();

Другие советы

So why won't you just create JavaScript function which will set the city and the countryName to your IDs (I suppose you will have id city and country, now you have the same id for both inputText). And just call it when the page is loaded, there two ways how to do it according this question.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top