Ajax.Updater and javascript

17 Mar 2009, by Michael Cindrić

Ran into a little problem today which made me think for a second. I have a Javascript function that runs once a calendar control is closed. It just passes a parameter to a action which renders a view nothing fancy.

So my onClose function looks like so

function onClose(cal) {
    var p = cal.params;
    new Ajax.Updater('overlapping', '/visits/new', {
      parameters: { start_date:  p.inputField.value; },
      evalScripts: true

This will fire once the calendar is closed. 'Overlapping' is the ID of the Div ill be updating and '/visits/new' is the path of the action in your controller. This will then pass the start date param to the action which can then be used in the view. The problem l had is that l had some javascript on the partial that was not executing. Had to think for a minute and then it turned out that evalScripts is false by default thus the javascript was not executing.

So its as simple as having the following as a param in your Ajax.updater

 evalScripts: true

Once you have done that your good to go.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.