function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AK_SmithAK_Smith 

run VF page onload

Hello!
How to run my page in SF1 "onload"?
geoFindMe() than save and than reload()
 
<apex:page standardController="Project__c" id="page" docType="html-5.0">
<p><button onclick="geoFindMe()">Show my location</button></p>
<p id="out"></p>
<script>

function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    document.getElementById('page:form:lati').value = latitude.toString().replace(".",",")  ;
    document.getElementById('page:form:long').value = longitude.toString().replace(".",",")  ; 


   
  };

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  };

  navigator.geolocation.getCurrentPosition(success, error);
}
</script>

<script>
function  reload(){
   sforce.one.back(true);
}
</script>

<apex:form id="form">


latitude :<apex:inputField id="lati"  value="{!Project__c.l__c}" /> 
longitude :<apex:inputField id="long" value="{!Project__c.ll__c}" />

<apex:commandButton action="{!save}"  value="Save" oncomplete="reload()"/>
           
          
            
</apex:form>

</apex:page>

Thank you!
Best Answer chosen by AK_Smith
sfdcMonkey.comsfdcMonkey.com
hi try below code :
 
<apex:page standardController="Project__c" id="page" docType="html-5.0">
<p><button onclick="geoFindMe()">Show my location</button></p>
<p id="out"></p>
<script>
  geoFindMe();
  callSave();
  reload();


function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    document.getElementById('page:form:lati').value = latitude.toString().replace(".",",")  ;
    document.getElementById('page:form:long').value = longitude.toString().replace(".",",")  ; 


   
  };

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  };

  navigator.geolocation.getCurrentPosition(success, error);
}
</script>

<script>
function  reload(){
   sforce.one.back(true);
}
</script>

<apex:form id="form">


latitude :<apex:inputField id="lati"  value="{!Project__c.l__c}" /> 
longitude :<apex:inputField id="long" value="{!Project__c.ll__c}" />

   <apex:commandButton action="{!save}"  value="Save" oncomplete="reload()"/>
      
   <apex:actionFunction name="callSave" action="{!save}" />           
</apex:form>

</apex:page>
i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi try below code :
 
<apex:page standardController="Project__c" id="page" docType="html-5.0">
<p><button onclick="geoFindMe()">Show my location</button></p>
<p id="out"></p>
<script>
  geoFindMe();
  callSave();
  reload();


function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    document.getElementById('page:form:lati').value = latitude.toString().replace(".",",")  ;
    document.getElementById('page:form:long').value = longitude.toString().replace(".",",")  ; 


   
  };

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  };

  navigator.geolocation.getCurrentPosition(success, error);
}
</script>

<script>
function  reload(){
   sforce.one.back(true);
}
</script>

<apex:form id="form">


latitude :<apex:inputField id="lati"  value="{!Project__c.l__c}" /> 
longitude :<apex:inputField id="long" value="{!Project__c.ll__c}" />

   <apex:commandButton action="{!save}"  value="Save" oncomplete="reload()"/>
      
   <apex:actionFunction name="callSave" action="{!save}" />           
</apex:form>

</apex:page>
i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
 
This was selected as the best answer
AK_SmithAK_Smith
Hey! Thank you!
Works only for the geoFindMe(). But the page did not close and did not update