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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:41:01+00:00 2026-05-23T22:41:01+00:00

I’ve seen a lot of examples that site how to use jQuery and .each()

  • 0

I’ve seen a lot of examples that site how to use jQuery and .each() to parse json arrays. What I want to do is use the .each() function to create the json. I’m getting input from the user regarding text boxes that will be used in an ajax call to sort a table. I am using .each() to find all text boxes that have valid input, and then I want to put that data into a json data type and send it via ajax to an SQL query. I’m not certain if I want an object vs. an array, and from what data I’ve parsed thus far, my object doesn’t seem to contain everything I’d expect.

I’ve created a global object to store the data, but a previous post on the web shows brackets, when everything I’ve seen for an array is parens ( ), and an object is curly braces { }. So my global ‘object’ (since I don’t know what to call [ ]) at this point looks like this:

var jsonFilter = [];

For the .each() function, that looks at user data ‘onkeyup’ to filter the list:

$("input:text[id^='filter']").live({
        focusin: function () {
            currentFilter = $(this).val();
            $(this).removeClass("filter");
            $(this).val("");
        },

        focusout: function () {
            if ($(this).val() == "") {
                // If they gave up focus and didn't type anything in the box, restore the text
                $(this).addClass("filter");
                $(this).val(currentFilter);
            }
        },

        keyup: function () {
            $("input:text[id^='filter']").each(function () {
                if ($(this).val() != "" && !$(this).hasClass('filter')) {
                    //alert("filterBy: " + $(this).attr('id') + "\nfilterValue: " + $(this).val());
                    jsonFilter.push({ filterBy: $(this).attr('id'), filterValue: $(this).val() });
                }
            });
            //alert("Done with .each()");
            filterReport(jsonFilter);
        }
    });

And for the array that is outputting the content of the jsonFilter:

function filterReport(_jsonFilter) {
        $("#jsonFilterLength").html(_jsonFilter.length);
        //$("#filterTest").html("");
        for (var i = 0; i < _jsonFilter.length; i++) {
            $("#filterTest").append("Index: " + i + ", filterBy: " + _jsonFilter[i]["filterBy"] + ", filterValue: " + _jsonFilter[i]["filterValue"] + "<br /><br />");
        }
    }

When I view the html in the div “#jsonFilterLength”, is see that the length is increasing, so it appears to be storing additional data. But the html in the div “#filterTest” only shows the data for the current text box I’m typing in, not what I would expect the entire json array to contain as I am trying to allow filtering on multiple text inputs simultaneously.

Regards,
Scott

  • 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-23T22:41:02+00:00Added an answer on May 23, 2026 at 10:41 pm

    Seems to be working for me.

    http://jsfiddle.net/WQjsN/2/

    Make sure you clear the jsonFilter variable on keyup function.

    You can also modify the code so that it’s shorter.

    Eg.

    for (var i = 0; i < _jsonFilter.length; i++) {
                var obj = _jsonFilter[i];
                $("#filterTest").append("Index: " + i + ", filterBy: " + obj.filterBy + ", filterValue: " + obj.filterValue + "<br /><br />");
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
i want to parse a xhtml file and display in UITableView. what is the

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.