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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:01:53+00:00 2026-05-28T00:01:53+00:00

I have a query builder form that allows a user to enter values into

  • 0

I have a query builder form that allows a user to enter values into fields that once complete allows them to pass the entered values to a search field. Not all the fields have to be completed by the user within the form.

sample of html

<div id="advanceSearchCriteria">
    <div class="searchHeader">Person</div>
    <div class="contentBorders" id="person">
        <div class="searchdiv">
            <span class="smLabel">Last Name</span><br />
            <input type="text" name="lastname" value="" size="15" />
        </div>
        <div class="searchdiv">
            <span class="smLabel">First Name</span><br />
            <input type="text" name="namefirst" value="" size="15" />
        </div>
        <div class="searchdiv">
            <span class="smLabel">Middle Name</span><br />
            <input type="text" name="namemiddle" value="" size="10" />
        </div>
        <div class="searchdiv">
            <span class="smLabel">Suffix</span><br />
            <input type="text" name="suffix1" value="" size="5" />
        </div>
</div>
</div>

Within jQuery I created a function to pass the values of the fields to an asp.net textbox control

    function setAdvancedSearchString() {
    checkField();
    var txt = $("input[name='tbsearchterm']");
    var fields = $("#advanceSearchCriteria :input").serializeArray();
    jQuery.each(fields, function (i, field) {
        if (txt) {
            txt.val(txt.val() + field.name + ": " field.value + " ");
        }
    });
}

With the current approach this returns all input fields and their values. What I would like to have is only fields that contain a value entered by the user to be serialized and passed to search term. For example if the user only entered last name I would only like that fieldname and value returned (lastname: james)

I’ve tried to test for null on the var fields but my syntax is wrong or I am testing for null in the wrong location

So far I have tried the following:

var fields = if($("#advanceSearchCriteria :input") != null) 
{
$("#advanceSearchCriteria :input").serializeArray();
}

but this seems to cause a compile error.

Can anyone provide some help on how to only serialize and return fieldnames and values that have a value entered?

Thank you,

  • 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-28T00:01:53+00:00Added an answer on May 28, 2026 at 12:01 am

    You can use attribute not equals selector to select fields with text and you don’t have to use .serializeArray(). Check this (example):

    function setAdvancedSearchString() {
       checkField();
       var txt = $("input[name='tbsearchterm']");
        $("#advanceSearchCriteria :input[value!='']").each(function(i, field) {
            txt.val(function(index, value) {
                return [value, field.name, ": ", field.value, " "].join('');
            });
        });
    }
    

    Extra
    I used an anonymous function for setting the value of txt and used array/join for string concatenation.

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

Sidebar

Related Questions

I have a form that allows the user to perform a myriad of searches.
I have a search form with a query builder. The builder is activated by
I have been hearing that the built-in query builder for the Entity Framework is
I have an object that has an instance of Doctrine\ODM\MongoDB\Query\Builder . When I serialize
I have a form that has all the fields pulled dynamic from a database
I am using in C# MYsql .I have query that works if I run
I've noticed that a few Wordpress blogs have query statistics present in their footer
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)

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.