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
punnoosepunnoose 

javascipt variable to apex variable

i have a variable in java script--- include2  i want to take that value into apex code i have written some piece of code found from discussion form but its not working .please tell me why?
  ------------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---------

AditiSFDCAditiSFDC

Try using actionFunction along with rerender attribute.

And  while calling javascript function on command button click use :

onclick="sendTimeStamp(); return false;"

punnoosepunnoose

Aditi thats not working.

We have a  problem now i have a value in javascipt i want to bring that to apex code.

Please do help to get over theh problem.

 

 

Punnoose

Alex.AcostaAlex.Acosta

I've had similar issues in the past when doing this. Try moving your javascript above your button. I'm not sure if it's just how the DOM is being generated with the tag library but this has sometimes resolved issues for me in the past.