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
shinerajbshinerajb 

javascript variable to apex variable

how do i pass a javascipt variable into apex variable.

Like i get the id corresponding to a checkbox in javascipt .how do i reflect it into apex varible

Regards

Shine

Best Answer chosen by Admin (Salesforce Developers) 
cml26sepcml26sep

You can use <apex:actionFunction> tag  in visualforce page which can be called from javascript and pass that javascript variable in that function and then in controller you can get that javascript variable and assign it to Apex variable.

All Answers

Anup JadhavAnup Jadhav
cml26sepcml26sep

You can use <apex:actionFunction> tag  in visualforce page which can be called from javascript and pass that javascript variable in that function and then in controller you can get that javascript variable and assign it to Apex variable.

This was selected as the best answer
WizradWizrad

Use javascript remoting.

 

It's the bee's knees.

shinerajbshinerajb

My apex code is given i want to display the value of include2 on button click it is not working.
with regards
Shine
  ------------Apex code---------
public string timestampValue{get;set;}
public new2(){
timeStampValue = 'm';
}
public void sendTimestamp()
{
    timestampValue='timestampValue--' + timeStampValue;
//system.debug('timestampValue' + timeStampValue);
}

}
------------Apex code---------
-------------javascript code---------
var include2='';
function showIndustriesId(theId,obj)
{
    if(obj.checked)
    {
        include2=include2.concat((','+theId));
        alert(include2);
    }
    else
    {
        include2=include2.replace((','+theId),'');
        alert(include2);
    }
}
function sendTimeStamp()
{
    var timeStamp=include2;
          sendTimeStamp(timeStamp);
}

-------------javascript code---------
-------------visual force---------
<apex:form >
  <apex:commandButton value="pass" onclick="sendTimeStamp()"/>
          <apex:actionFunction name="sendTimeStamp" action="{!sendTimeStamp}" >
    <apex:param name="x" value="" assignTo="{!timeStampValue}" />
</apex:actionFunction>
    </apex:form>
-------------visual force---------

shinerajbshinerajb

Hai,

 

How can we use this  javascript remoting.