You need to sign in to do that
Don't have an account?
CB312
Passing an HTML input to Apex controller
Hi,
I have an html input that I would like to pass to my apex controller. How can I have APEX access the value?
Sanitized code below, I am trying to pass the "rep2" field to my controller.
Sanatized code here, I'm using JQuery Autocomplete to populate the field.
VF Page:
$j(document).ready(function() { $j("#rep2" ).autocomplete({ 'source': replist }); }); <apex:form > <apex:pageBlock > <div class="ui-widget"> <label for="rep2"><b>Reassign to: </b></label> <input id="rep2"/> </div> <apex:pageBlockButtons > <apex:commandButton action="{!updateLeadOwner}" value="Save" rerender="leadtoupdatetable"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form>
Controller:
public pagereference updateLeadOwner() { id leadid = ApexPages.currentPage().getParameters().get('id'); string repname = Apexpages.currentPage().getParameters().get('rep2'); system.debug('-----------------DEBUG-------------'); system.debug(repname);
repname return null, what is the best way to access the value?
Thanks!
-Chris
try this , I have picked your example and used a apex:inputHidden and assigned it value of your html input and passed it to contrller
Contrller : In this i used add error just to show the value in pageMessage so that it confirms that value is passed
VFP : In java script function i used the id for hidden in my example if it is something else then change in your case, pick it from view source.
You can replicate this for you, let me know if any issues in it.
All Answers
Why dopn't you use an apex:inputText for the field and bind it to a controller property? That's the usual way to get data from the page to the controller. Should b e tons of examples in our doc....
Thanks but the reason I am not using Apex:input text is I want to leverage the JQuery Autocomplete function and from what I've read (and tried) it doens't work with apex.
ie. if I change
to:
the JQuery autocomplete functionality breaks. Any other ideas, either how to get JQuery to work with Apex components or how to get the input value?
-Chris
try this , I have picked your example and used a apex:inputHidden and assigned it value of your html input and passed it to contrller
Contrller : In this i used add error just to show the value in pageMessage so that it confirms that value is passed
VFP : In java script function i used the id for hidden in my example if it is something else then change in your case, pick it from view source.
You can replicate this for you, let me know if any issues in it.