+ Start a Discussion
Nikunj VNikunj V 

apex:action function problem

Hey,
I am using apex:action 2 times. it is calling wrong action function everytime.

Here is the code
 
<apex:page standardController="Project__c" sidebar="false" showHeader="true" extensions="test3">
<apex:includeScript value="{!$Resource.modernizr}"/>
<script>
function doTheGeoThang() {
if (Modernizr.geolocation){
navigator.geolocation.getCurrentPosition(
function(position) {
findMe(position.coords.latitude,position.coords.longitude);
}
);
} else {
alert ("Your browser isn't hit. Upgrade man!");
}
}
</script>
<apex:form >
<apex:pageBlock >

<apex:actionRegion ><b><span style="cursor: pointer;"
onclick="doTheGeoThang()">
<center>Punch In</center>
</span>
</b><br/><br/>
<apex:actionFunction name="findMe" action="{!PunchIn}" rerender="jsvalues">
<apex:param name="lat" value="" assignTo="{!valueLat}"/>
<apex:param name="long" value="" assignTo="{!valueLong}"/>
</apex:actionFunction></apex:actionRegion>
</apex:pageBlock></apex:form>



<apex:form ><apex:actionRegion >
<b><span style="cursor: pointer;"
onclick="doTheGeoThang()">
<center>Punch Out</center>
</span>


</b><br/><br/>
<apex:actionFunction name="findMe" action="{!PunchOut}" rerender="jsvalues">
<apex:param name="lat" value="" assignTo="{!valueLat}"/>
<apex:param name="long" value="" assignTo="{!valueLong}"/>
</apex:actionFunction></apex:actionRegion>
</apex:form>


</apex:page>


here, when i click on punchin, it is calling punchout apex:actionfunction instead of punchin. i tried pageblock, apex:region , but everytime it is calling wrong method. please help me out here. 


Thanks
Best Answer chosen by Nikunj V
surasura
your both action functions have the same name findMe give different names to two functions and call the correct function by name
 
<apex:page standardController="Project__c" sidebar="false" showHeader="true" extensions="test3">
<apex:includeScript value="{!$Resource.modernizr}"/>
<script>
function doTheGeoThang() {
if (Modernizr.geolocation){
navigator.geolocation.getCurrentPosition(
function(position) {
findMe2(position.coords.latitude,position.coords.longitude);
}
);
} else {
alert ("Your browser isn't hit. Upgrade man!");
}
}
</script>
<apex:form >
<apex:pageBlock >

<apex:actionRegion ><b><span style="cursor: pointer;"
onclick="doTheGeoThang()">
<center>Punch In</center>
</span>
</b><br/><br/>
<apex:actionFunction name="findMe2" action="{!PunchIn}" rerender="jsvalues">
<apex:param name="lat" value="" assignTo="{!valueLat}"/>
<apex:param name="long" value="" assignTo="{!valueLong}"/>
</apex:actionFunction></apex:actionRegion>
</apex:pageBlock></apex:form>



<apex:form ><apex:actionRegion >
<b><span style="cursor: pointer;"
onclick="doTheGeoThang()">
<center>Punch Out</center>
</span>


</b><br/><br/>
<apex:actionFunction name="findMe1" action="{!PunchOut}" rerender="jsvalues">
<apex:param name="lat" value="" assignTo="{!valueLat}"/>
<apex:param name="long" value="" assignTo="{!valueLong}"/>
</apex:actionFunction></apex:actionRegion>
</apex:form>


</apex:page>