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
anukarthi_nimmalaanukarthi_nimmala 

Pass Javascript variable to Apex controlller

Hi Everyone,

 

I actually need to pass javascript variable to apex controller.I tried to pass it by using apex:actionfunction.But its not working properly.So please someone help me ourt of this issue .I ju8st want to pass the javascript variable in to apexcontroller.

 

So help me please.

 

 

 

                                                                                                                                                                        Thanks and regards,

 

                                                                                                                                                                                  Anu..

 

 

SargeSarge

Hi Anu,

 

   Can you please post the code so that someone can find out what is the difficulty.  Also I am not sure if you have visited this content posted by Dave Caroll http://blog.sforce.com/sforce/2009/10/passing-javascript-values-to-apex-controller.html. I personally have tried this and this is working for me. 

  Just see if you can get to know what is the problem in your code after visiting the site. Else post your code.

 

 

Cheers..

anukarthi_nimmalaanukarthi_nimmala

Hi Sarge,

 

  Thanks a lot for your help.But that could even though i tried its not helping me out from the issue.

 

So please check my code and help me out to solve d issue

 

My Controller as follows

 

public class passjsvar
{

String xcon;

public String getxcon()
{
  return xcon;

}

public void setxcon(String s)
{
  this.xcon=s;
}

position__c pos=new Position__c();
public PageReference dostuff()
{
  // xcon=Apexpages.currentPage().getParameters().get('xrep');
   try
   {
   pos.testeditor__c=xcon;
     insert pos;
   }
   
   catch(exception ex1)
   {
   }
  return null;
}


}

 

 

 

Visualforce page:

 

 

<apex:page controller="passjsvar" action="{!dostuff}" >
  <script>
  function passvar()
  {
    var x='abc';
    
    dostuff(x);
  return x;
 
 
  }
    </script>
 


 
 
  <apex:form >
  <apex:pageBlock id="rer" rendered="true">
<apex:outputpanel id="result">
   {!xcon}
</apex:outputpanel>
  <apex:actionFunction name="dostuff" action="{!dostuff}" reRender="result" >
    <apex:param name="xrep" value="xrep"  assignTo="{!xcon}"/>
  </apex:actionFunction>
  </apex:pageBlock>
    <apex:commandButton value="saveto"  action="{!dostuff}"  onclick="passvar()" reRender="result"/>
 
  </apex:form>
 

 
 
 
 
 
</apex:page>

 

 

 

Here iam trying to pass var x from javascript to controller.Iam trying to insert that var in my custom object .

 

But wen iam trying for that requirement with the following code iam not able to do it.I dont know where iam going.

 

So please help me top solve the issue.

 

                                                                                                                                                                               Thanks and regards,

                                                                                                                                                                                         Anu.

baller4life7baller4life7

I would be interested in the answer, too!