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

  • SEARCH
  • Home
  • 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 6081249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:09:17+00:00 2026-05-23T11:09:17+00:00

What is wrong with my jquery plugin when I make the function inside the

  • 0

What is wrong with my jquery plugin when I make the function inside the plugin with $.fn.

You can see it what I mean here. I have two forms and they share the same plugin,

     $(document).ready(function(){

        $("#search-title").post_form_public();
        $("#subscribe-email").post_form_public();

    });

The first form won’t be working again when the second form is triggered.

It works fine if I attach plugin to one form only.

Below are some more details inside the plugin code,

post_form_public: function(options) {

    // Set the default values, use comma to separate the settings, example:
    var defaults = {
        top:            250, // The top of the proceesing popup and the result popup.
        width:          400 // The width of the proceesing popup and the result popup.
    }

    var options =  $.extend(defaults, options);
    var o = options;

    var $cm = this.submit(function(e){

        var object = $(this);

        // Get the path from attribute of action in the form.
        var target_postpath = object.attr('action');
        var top = o.top;
        var width = o.width;

        // Keep the lines below for checking.
        alert($cm.selector);

        // Disable the submit button so that you won't click it twice while the ajax is processing the form.
        // Must use true or false for jquery > 1.6.
        $('input[type=submit]',$($cm.selector)).attr('disabled', true).css({opacity:0.4});

        // Post the form .
        $.post(target_postpath,object.serialize(),function(xml){

            //process_posted(xml); // two forms work fine with this!
            $.fn.post_form_public.process_posted(xml); // but not with this!

        });

        return false;

    });

    // Callback function for proccesing the deleted item.
    //function process_posted(xml)
    $.fn.post_form_public.process_posted = function(xml)
    {

        // Enable the submit button again after processing the xml output.  
        // Must use true or false for jquery > 1.6.
        $('input[type=submit]',$($cm.selector)).attr('disabled', false).css({opacity:1});

    }

}

But if I just make the function without $.fn., then these two forms will work fine. How can I use $.fn. and make the multiple forms worked!?

or you can see the code here.

Thanks.

  • 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-23T11:09:17+00:00Added an answer on May 23, 2026 at 11:09 am

    The variable

    $.fn.post_form_public.process_posted
    

    …can only store one function. The second time you call your plugin, this will be overwritten. In the form that works, you have a function that forms a closure over the value of the $cm variable – and you have one of these functions created for each call to post_form_public.

    What’s the matter with the form of the function that worked?

    One method to store it in your post_form_public object might be something like:

    if(!$.fn.post_form_public.process_posted) $.fn.post_form_public.process_posted = {};
    $.fn.post_form_public.process_posted[$cm.selector] = function(xml) {
      //...
    };
    

    …and call it within your post callback with:

    $.fn.post_form_public.process_posted[$cm.selector](xml);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats wrong with my buttons? here http://hiddenbrookstudio.com/index.swf , see how they rollover and dissappear
I am trying to make use of qTip JQuery plugin . I have tried
Hi can someone tell me what i'm doing wrong in this jquery statement. I
What am I doing wrong here? I'm trying to get started with jQuery UI
I'm working on a jQuery plugin and can't seem to override the default settings,
How do I make a jQuery function work with Grails?? I installed the jQuery
I'm trying to use the jQuery Validation plugin to make a multistep form with
I am using galleria jquery plugin. I have a div with class carousel, This
I am using this jQuery plugin: http://api.jquery.com/slideToggle/ I have this code: <div id=panel><form action=postit.php
I have a problem with jquery plugin called quikflip. Basically, the plugin flips an

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.