You need to sign in to do that
Don't have an account?
Shohrat Muhamov
Pass value from JavaScript to Controller
Hello,
I need to pass user input from javascript in visualforce button to Apex controller, to add it to field. Can anyone hep me with it please?
I need to pass user input from javascript in visualforce button to Apex controller, to add it to field. Can anyone hep me with it please?
https://ohotech.com/2015/04/pass-value-of-variables-from-visualforce-to-controller-via-javascript.html
https://www.jitendrazaa.com/blog/salesforce/passing-parameter-in-actionfunction-in-visualforce/
For additional info
https://gist.github.com/sravalaparthi/97e171a4025e6e271387
https://developer.salesforce.com/blogs/developer-relations/2009/10/passing-javascript-values-to-apex-controller.html
You can pass the value from javascript to controler by action function:
Please have a look at this code:
<apex:page showHeader="true" sidebar="true" controller="SampleController">
<script type="text/javascript">
window.onload = function(){
//this is calling the apex:actionFunction below with the same name when the page loads
setUserLocation('11,13');
console.log('setUserLocation called');
}
</script>
<apex:form >
<!-- this action function can be called from javascript -->
<apex:actionFunction name="setUserLocation" action="{!setUserLocationInApex}" rerender="">
<apex:param name="userLocation" value="" />
</apex:actionFunction>
</apex:form>
For more infomation you can also refer to this link:-
https://salesforce.stackexchange.com/questions/24666/how-to-pass-javascript-value-to-controller
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
I have tried your method before, but it didn't work for me. I am using promt function from java script to get user input.
Best Regards,
Shohrat Muhamov
You can use remoting action to pass data from javascript to Apex controller. Please try the below code and let me know if this works for you.
Apax Page:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi