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 4324548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:08:51+00:00 2026-05-21T09:08:51+00:00

I have made my own jQuery plugin, but it has problem that values I

  • 0

I have made my own jQuery plugin, but it has problem that values I set in form are not found in form when I try to generate query string from form. Test it here http://jsfiddle.net/z3Yff/3/.

(function($) {

    $.fn.ajaxSubmit = function( options ) {
        // Plugin settings
        var settings = {
            beforeFunction : function() {},
            afterFunction : function() {}
        };

        // Override options
        if ( options ) { 
            $.extend( settings, options );
        }

        // Set variables
        var self = this;

        // Check that form value is set
        var checkValue = function(value) {
            if(value != undefined && value != null)
            {
                return true;
            }
            return false;
        };

        // Catch submitting input/button
        var submitInputName;        
        $("button, input[type=submit]", this).live("click", function() {
            submitInputName = $(this).attr("name");
        });

        // Submit form
        var submitForm = function(form) {        
            var method = form.attr("method");
            if(!checkValue(method) || method.length == 0) method = "post";
            var action = form.attr("action");
            var query = "";
            var i = 0;
            $("input, button, textarea", $(this)).each(function(index) {
                var name = $(this).attr("name");
                var value = $(this).attr("value");
                var type = $(this).attr("type");
                if(checkValue(value) && checkValue(name))
                {
                    if(i > 0)
                    {
                        query = query + "&";
                    }
                    query = query + name + "=" + value;
                    i++;
                }
            });
            alert(query); // This is empty String, but it should contain values I enterd to form
            return $.ajax({
                type: method,
                cache: false,
                url: action,
                data: query,
                async: false
            }).responseText;
        };

        // Add ajax submit catching
        this.submit(function() {
            options.beforeFunction();
            submitForm($(this));
            options.afterFunction();
            return false;
        });
    };

})(jQuery);
  • 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-21T09:08:52+00:00Added an answer on May 21, 2026 at 9:08 am

    Your immediate problem is in your checkValue function. This conditional will always be false:

    if(value != undefined && value != null && name != undefined && name != null)
    

    because you’re not passing name into the function; the above is logically equivalent to this:

    var name;
    if(value != undefined && value != null && name != undefined && name != null)
    

    Just as a style note, you could write it as:

    function checkValue(value) {
        return typeof value != 'undefined' && value != null;
    }
    

    There is no special undefined value or keyword in JavaScript. When you say x != undefined you’re actually implicitly creating a variable called undefined that is not initialized, hence the typeof value != 'undefined' instead of your value != undefined.

    There are other problems. For one, you’re skipping over <select> elements. For another, you’re not checking the type of <input> elements so you’ll include the values of checkboxes and radio buttons that are in the form but not selected.

    Furthermore, you’re using the wrong thing in your .each, you want $(form) rather than $(this) so this:

    $("input, button, textarea", $(this)).each(function(index) {
    

    should be this:

    $("input, button, textarea", $(form)).each(function(index) {
    

    I didn’t fix the <select>, radio button, or checkbox issues but this version is at least producing a query string: http://jsfiddle.net/ambiguous/8QYWH/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have made a webservice that interfaces with a set of data contained
I have a class library that has it's own model and connectionstring to the
I have a JavaScript class that I have made and put it into its
I have been trying all afternoon to get the jQuery Sifr Plugin ( http://jquery.thewikies.com/sifr/
Hi i have made my own UserControl, its a little windows explorer. i defined
I made a form using Javascript and HTML and have a send button on
I have problem with a fullscreen Flash video. I made a custom Flash video
I have made a SVG image, or more like mini application, for viewing graphs
I have made some code which exports some details of a journal article to
I have made a custom UserControl i Vb.net (windows application). How can I add

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.