Visual Force page help: Problem passing values from select box to controller
-
12-10-2019 - |
Pergunta
I have Vf page with 2 select boxes one for project and other for milestones. I want to pass these values to method in the controller. This controller method returns a string which needs to used in javascript. All these needs to happen on click of submit button. What i currently have is that the string which is used by the javascript is created in the constructor of the class and i am referencing the string directly from the javascript .
I think the problem is coz i am writing the code to generate the string consumed by javascript in the constructor and to generate the code i need to use the select box values. These values are not populated when the constructor is run.
For this i can move this code into an method in controller. But the question for me is how do i pass these apex select box values into the controller method and then run a javascript function after the controller method is run.
Thanks
Prady
Solução
You can use a combination of onclick
, rerender
and oncomplete
to pass data back and forth between JavaScript and your controller. The mighty Jeff Douglas has a great example at http://blog.jeffdouglas.com/2011/01/17/passing-values-to-javascript-from-apex-controller-method/
Outras dicas
Create a <apex:inputHidden id="hiddenField" value="{!stringValue}"/>
now access it by
document.getElementById("{!$Component.myForm.hiddenField}").value
<apex:page>
<apex:form id ="myForm">
<apex:inputHidden id="hiddenField" value="{!stringValue}"/>
<apex:form>
</apex:page>