Thursday, April 28, 2011

Drupal Form can't access javascript function (errors "not a function")

using drupal with lightbox2 to open a form. this form is from a custom module.

the module has a setting: 'onsubmit' => 'return form_submission(this);' and that appears to be working correctly.

I've included the functions.js in the theme.info file and it's showing up, i can open that file and see the function.

for some reason, i keep getting "form_submission not a function" when i do submit the form.

if(Drupal.jsEnabled)
{
$(document).ready(function() {
    // Call back function for AJAX call

        var form_submission = function(responseText) {
            alert (responseText); 
        }

        // preventing entire page from reloading
        return false;
    });

}
From stackoverflow
  • form_submission has to be a defined function.

    function form_submission(data) {
       // action code
    }
    

    or also try

    var form_submission = new function(data) {
       // action code
    }
    
    eriksays : thanks -- but something else is going on. i can add the function between script tags right above the form and still no luck. i tried both function declaration techniques you mentioned
    Kevin : If you put an alert right after if(Drupal.jsEnabled), does it appear? Is that condition true?
  • Not that this is the perfect answer, but I removed the function from within the document.ready jquery wrapper and it picked up on it.

0 comments:

Post a Comment