1

I have a javascript that works if I place it in a mark up in my webform but breaks the form if I make the form a multipage. If I place the script as it's own file and then call it using drupal_add_js(path_to_theme() .'/scripts/SCRIPT_NAME.js'); in my webform-form-NID.tpl.php nothing hapens.

Here is my script in my markup:

$(document).ready(function(){ var ac_config = { source: "/example/sites/all/themes/skeletontheme/js/democities.php", select: function(event, ui){ $("#edit-submitted-info-company").val(ui.item.company); $("#edit-submitted-info-address").val(ui.item.address); $("#edit-submitted-info-address2").val(ui.item.address2); $("#edit-submitted-info-city").val(ui.item.city); $("#edit-submitted-info-state").val(ui.item.state); $("#edit-submitted-info-zip").val(ui.item.zip); }, minLength:1 }; $("#edit-submitted-info-company").autocomplete(ac_config); });

In the stand alone .js file: (function($){ var ac_config = { source: "/example/sites/all/themes/skeletontheme/js/democities.php", select: function(event, ui){ $("#edit-submitted-info-company").val(ui.item.company); $("#edit-submitted-info-address").val(ui.item.address); $("#edit-submitted-info-address2").val(ui.item.address2); $("#edit-submitted-info-city").val(ui.item.city); $("#edit-submitted-info-state").val(ui.item.state); $("#edit-submitted-info-zip").val(ui.item.zip); }, minLength:1 }; $("#edit-submitted-info-company").autocomplete(ac_config); });

First question is why does the script not work if I add page breaks to my webform.

Second question - why won't the script work the way I have it formatted as it's own .js file.

Thanks for any assistance.

2 Answers 2

0

I think you can use default druypal behaviors

  Drupal.behaviors.mywebform = {
      attach: function (context, settings) {
    var ac_config = {
            source: "/example/sites/all/themes/skeletontheme/js/democities.php",
            select: function(event, ui){
                $("#edit-submitted-info-company").val(ui.item.company);
                            $("#edit-submitted-info-address").val(ui.item.address);
                            $("#edit-submitted-info-address2").val(ui.item.address2);
                            $("#edit-submitted-info-city").val(ui.item.city);
                $("#edit-submitted-info-state").val(ui.item.state);
                $("#edit-submitted-info-zip").val(ui.item.zip);
            },
            minLength:1
        };
        $("#edit-submitted-info-company").autocomplete(ac_config);
        }
    }

Hope it will help!

0
0

I'm not sure about the answer to your first question - but it might be fixed by this:

Regarding your second question, you need to use a wrapper with your javascript, take a look at 'Working with JavaScript and jQuery', about four screens down, it has a great explanation and gives some good examples.

Specifically, the part about 'JavaScript behaviors / JavaScript on AJAX forms'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.