You need to sign in to do that
Don't have an account?
Urgent : javascript variable to apex variable
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---------
http://blogs.developerforce.com/developer-relations/2009/10/passing-javascript-values-to-apex-controller.html
All Answers
Hi
U can do like this
<apex:inputHidden value="{!YourObject.field}" id="theField1" />
<script> var theField1 = document.getElementById('{!$Component.theField1}'); </script>
<apex:commandButton onclick="theField.value=include2;" action="{!save}" value="save" />
Regards,
Rajesh.
I have tried this code block and using onclick="sendTimeStamp(); return false;"/> will solves your problem.
Hai Aditi,
I tried this,but its not coming
Hai,
We have values in javascript ,I want to get those values in an apex variable
http://blogs.developerforce.com/developer-relations/2009/10/passing-javascript-values-to-apex-controller.html
Another solution is to use the <apex:Param /> Tag.
You can find more about this tag by going to http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm
But here's a snipet of how it should look like using VisualForce's Tag Library to assign value to your apex variable in your controller.