You need to sign in to do that
Don't have an account?
Passing JavaScript Variables into a Controller
The first thing I did was read this post on http://blog.sforce.com/sforce/2009/10/passing-javascript-values-to-apex-controller.html
Here I thought I was doing everything right but I can't get the values to actually pass in.
The page itself lists out a grid of various records in a table, with one input text field per row. I want it so if they enter a value in one of the boxes, it will add it to a list of new entries to make. So the onchange event runs to add it to the list, and there is a save method that happens later that will store all of the values in lstTimeToEnter
This is the VisualForce code
<apex:actionFunction action="{!CreateTimeEntryRecord}" name="enterTime"> <apex:param name="insertTimeTask" value="" /> <apex:param name="insertTimeWork" value="" /> </apex:actionFunction> <apex:inputText id="TimeEntry" onchange="enterTime({!lstTasks.ID}, this.value)"></apex:inputText>
This is the Apex Code
public PageReference CreateTimeEntryRecord() { insertedTimeTaskID = Apexpages.currentPage().getParameters().get('insertTimeTask'); insertedTimeWorked = decimal.valueOf(Apexpages.currentPage().getParameters().get('insertTimeWork')); insertedTimeDate = date.today(); Time_Entry__c objNewTimeEntry = new Time_Entry__c(Task__c=insertedTimeTaskID, Date_Worked__c=insertedTimeDate, Time_Worked__c=insertedTimeWorked); lstTimeToEnter.add(objNewTimeEntry); return null; }
I'm sure I'm missing something simple and would appreciate any help.
Try adding a rerender attribute to your actionfunction - I've found that parameters only go back to the controller if there is a rerender (which I guess equals an ajax request).
I've got a number of pages where the entire content is surrounded by an outputpanel that is rerendered by my actionfunction/commandbutton etc.
All Answers
Try adding a rerender attribute to your actionfunction - I've found that parameters only go back to the controller if there is a rerender (which I guess equals an ajax request).
I've got a number of pages where the entire content is surrounded by an outputpanel that is rerendered by my actionfunction/commandbutton etc.
I reckon you'll also want to surround your id with quotes, e.g.
That did the trick. Funny enough I'm just passing the User.ID into it and it works. I just grabbed a variable to see what would work and it did.
Thanks