Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:46:34+00:00 2026-05-15T15:46:34+00:00

I have a plugin that I can set settings and call it when document

  • 0

I have a plugin that I can set settings and call it when document ready. However, I want to change it to an “onclick” of a button instead of DOM ready.

the plugin goes like

(function($) {

$.fn.addressSearch = function(settings) {

    settings = jQuery.extend({
        searchClass: "quickSearch",                             
        checkElement: "href",                                   
        dataElement: "data",                                   
        countryListClass: "countryList",                       
        countryCode: "11455",                                   
        errorMsg: "You can only search for address in the UK.",
        houseNumberClass: "TextboxHouseNumber",                 
        postcodeClass: "postcode",                              
        addressLine1Class: "addSearchLine1",                    
        addressLine2Class: "addSearchLine2",                    
        addressLine3Class: "addSearchLine3",                   
        addressTownCityClass: "addTownCity",                    
        ajaxUrl: "/WebService/addressLook",               
        submitType: "POST",                                     
        dataType: "xml",                                       
        parameters: "",                                         
        addressProcessURL: "",                                  
        callbackFunctionSingleAddress: selectAddress,           
        callbackFunctionMultipleAddress: quickBoxSearch,        
        useExternalProcessPage: false,                          
        validateCountry: true                                   

    }, settings);

    var jQueryMatchedObj = this;                                

    function _initialize() {
        _startModal(this, jQueryMatchedObj);                    
        return false;                                           
    }
    function _startModal(objClicked, jQueryMatchedObj) {
        $j(objClicked).addClass(settings.searchClass);

        var countryList = "." + settings.countryListClass + "";

        if (settings.validateCountry) {
            if ($j(countryList) && $j(countryList).val() != settings.countryCode) {
                alert(settings.errorMsg);
                return false;
            }
        }

        if (settings.parameters) {
            $j.ajax({
                url: settings.ajaxUrl,
                type: settings.submitType,
                dataType: settings.dataType,
                data: settings.parameters,
                success: function(res) {
                    var addresses = eval(res.getElementsByTagName('string')[0].firstChild.data);
                    if (addresses.length == 0)
                        alert('Your address could not be found, please enter it manually');
                    else if (addresses.length == 1) {
                        settings.callbackFunctionSingleAddress(
                            addresses[0].addressLine1,
                            addresses[0].addressLine2,
                            addresses[0].addressLine3,
                            addresses[0].town,
                            settings.TextboxHouseNumber,
                            settings.postcodeClass,
                            settings.addressTownCityClass,
                            settings.addressLine1Class,
                            settings.addressLine2Class,
                            settings.addressLine3Class
                            );
                    } else if (addresses.length > 1) {
                        settings.callbackFunctionMultipleAddress(
                            settings.callbackFunctionSingleAddress,
                            addresses,
                            settings.useExternalProcessPage,
                            settings.TextboxHouseNumber,
                            settings.postcodeClass,
                            settings.addressTownCityClass,
                            settings.addressLine1Class,
                            settings.addressLine2Class,
                            settings.addressLine3Class
                            );
                    }
                }
            });
        }
        return false;
    }
    //return this._initialize();
    return this.unbind('click').click(_initialize);
}
})(jQuery);

this works wihtout any problem when call on DOM ready I call it as below;

$("#mydiv").addressSearch({
   searchClass:"foo",
});

I want to call this on the onclick of the same div. how do i do it? when I try below it says “addressSearch undefined”

$("#mydiv").click(function(){

  addressSearch({
    searchClass:"foo",
  });

});

Where have I gone wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:46:35+00:00Added an answer on May 15, 2026 at 3:46 pm

    Well you’ve written a plugin, so you have to use it like part of jQuery.

    $('#mydiv').click(function() {
      $(this).addressSearch(/* ... */);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.