+ Start a Discussion
Bryant Daniels 46Bryant Daniels 46 

set apex param values from javascript DOM

Hello I was trying to figure out how i can set the value on a Apex Param 
here is my visualforce:

<button onclick="done();" class="btn btn right" type="button" id="doneButton" style="border: none; background: none; width: 100px; background-color: #dcdcdc; color: #ffffff;">Done</button>
                     <apex:actionFunction action="{!done}" name="SetHiddenValue" reRender="">
                        <apex:param name="brandCode" value="" assignto="{!iaFet.Brand_CD__c}" id="brandCode" />
                    </apex:actionFunction>
and my java script where i get the values that i need:
function getRequiredValues(){
                var brandCodeVal  = $('#brandDropdown option:selected').val();                            
                console.log(brandCodeVal);
               
            }
when i run this i get the value that i want in the console.log but i am trying to figure out how i can pass that value to the apex: param value so then i can assign it to something in my controller and save the record with the value. 
Alex SelwynAlex Selwyn
You need to call the actionFuntion using it's name. 
 
<button onclick="done($('#brandDropdown option:selected').val(););" class="btn btn right" type="button" id="doneButton" style="border: none; background: none; width: 100px; background-color: #dcdcdc; color: #ffffff;">Done</button>
                     
//changed the name to done
<apex:actionFunction action="{!done}" name="done" reRender="">
                        <apex:param name="brandCode" value="" assignto="{!iaFet.Brand_CD__c}" id="brandCode" />
                    </apex:actionFunction>

Or you can call the javascript function and call the action function from within the javascript
<button onclick="getValueAndCallDone();" class="btn btn right" type="button" id="doneButton" style="border: none; background: none; width: 100px; background-color: #dcdcdc; color: #ffffff;">Done</button>
                     <apex:actionFunction action="{!done}" name="done" reRender="">
                        <apex:param name="brandCode" value="" assignto="{!iaFet.Brand_CD__c}" id="brandCode" />
                    </apex:actionFunction>


function getValueAndCallDone(){
                var brandCodeVal  = $('#brandDropdown option:selected').val();      
                //do something more here.                      
                done(brandCodeVal);
               
            }

Hope that helps!

 
Bryant Daniels 46Bryant Daniels 46
Thanks for the quick response unfortuantly that didn't help, but I was able to get it working.