Hey everyone, I have a small plugin that I wrote that makes a normal
form into an ajax form.  I also want the user to be able to pass some
ID's to the plugin so that they can return specific content in the
server response and place it on the page.  But, if the user chooses to
leave that blank they should be able to, this where my problem is.
Right now, I have html for the findTarget, and it seems to work ok,
since both are not filled in, but I am not sure if this is the most
efficient way to do this.  Any ideas of how I could write this better?

$.fn.testform = function(options) {
    var defaults = {
        findCreated: '',
        findTarget: 'html',
        loading: ''
    };

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

    return this.each(function() {

        var obj = $(this);
        var itemId = obj.attr('id');
        var itemHref = obj.attr('action');
        obj.removeAttr('onsubmit');
        $('#sq_commit_button').removeAttr('onclick');

        $('#sq_commit_button').click(function() {
            var serializeForm = obj.serialize();
            $.ajax({
                type: 'POST',
                url: itemHref,
                                data: serializeForm,
                beforeSend: function() {
                    $(defaults.findTarget).show();
                },
                success: function(html) {
                                        if (defaults.findCreated != '' && 
defaults.findTarget != '') {
                    $(defaults.findTarget).html($
(html).find(defaults.findCreated));
                    //$("#loadingImage").hide();
                    setTimeout(function() {
                        $(defaults.findTarget).fadeOut('slow',
                        function() {
                            $(this).html('')
                        });
                    },
                    5000);
                                        }
                }
            });
        });
    });
};

Reply via email to