Javascript works inline in webform but not as standalone 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.
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!