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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:56:22+00:00 2026-06-04T19:56:22+00:00

I am new to jQuery and I ran into a problem that is probably

  • 0

I am new to jQuery and I ran into a problem that is probably easy to spot for most of the frontend gurus out here.

I created the following script

$(document).ready(function() {
    $("#facet_properties input[type='checkbox']").each(function() {
        $(this).click(function() {
            var queryString = getQueryString();
            $('body').load(window.location.pathname.concat(queryString));
        })
    });
});

function getQueryString() {
    var queryString = "";
    var queryStringBegun = false;
    $("#facet_properties input[type='checkbox']").each(function() {
        if ($(this).is(':checked')) {
            var checkboxFullName = $(this).attr('name');
            var checkboxName = checkboxFullName.substr(checkboxFullName.lastIndexOf('_') + 1);
            var concatenationCharacter = '&';
            if (!queryStringBegun) {
                concatenationCharacter = '?';
            }
            queryString.concat(concatenationCharacter).concat(checkboxName);
            queryStringBegun = true;
        }
    });

    return queryString;
}

I am trying to create a query string variable in the getQueryString method, but somehow queryString stays empty. When a checkbox is checked I see the statement queryString.concat(concatenationCharacter).concat(checkboxName); is reached and I see that ‘concetenationCharacter’ and ‘checkboxName’ have the correct value. So why does my function return “”?

This is probably a variable scoping issue or something. I am guessing it’s something simple. 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-06-04T19:56:24+00:00Added an answer on June 4, 2026 at 7:56 pm

    concat() doesn’t alter the original string. You have to assign the return value back to the variable: queryString = queryString.concat(concatenationCharacter).concat(checkboxName);

    Using concat() is a bit of an overkill, though: you can concatenate strings simply with the + operator:

    queryString += concatenationCharacter + checkboxName;
    

    Not related to the problem, but you can shorten the code you have by moving the .is(':checked') check from the function to the selector:

    $("#facet_properties input[type='checkbox']:checked").each(function() {
        ...
    

    You also don’t need to attach the click event to each element individually. You can again just use the selector. Using a variable in the event is also a bit unnecessary (unless you have more use for it in the actual app).

    $(document).ready(function() {
        $("#facet_properties input[type='checkbox']").click(function() {
            $('body').load(window.location.pathname + getQueryString() );
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone else ran into the problem where jQuery scripts such
Ran into problem with creating custom select dropdown plugin in jQuery. I'm at the
I am a bit new to reusable plugins for jquery. I have ran across
When writing a new jQuery plugin is there a straightforward way of checking that
I have application that brings response via Ajax and creates 5-20 new jQuery click
Fairly new to Jquery here.... but one thing I have been told and being
I ran into a problem deploying on Heroku do to a failure in the
What's the easiest way to define a new jQuery member function ? So that
I have many instances of the same type of problem using jQuery. Probably because
While working with some jQuery ajax, I've run into this problem with Chrome and

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.