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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:55+00:00 2026-05-26T20:27:55+00:00

within a form I have a section that allows the user to build out

  • 0

within a form I have a section that allows the user to build out a search query. Within the options the user has the ability to select different operators ( contains, does not contain, like, between).

When the user selects between I insert a new input field after the drop down menu which would server as a to from field see image:
enter image description here

The issue I am having is how I am testing for the existence of the field. Currently I am doing this based upon the value of the object. This approach does not work if the field was not originally set to between. I.E if it is on contains and I select like the field is removed.

I think I need to count the number of text input fields in the current div and then if the number is greater than 2 remove one otherwise do nothing.

Where I am stuck is in the ability to count the input elements for the current div

I have tried:

var cnt = $(this, 'div .operClass input:text').length;

but this counts all inputs in the form vs the current row.

Can anyone point me in the right direction on when an option is selected to count and return the number of input fields for the current div that the selector is inside?

Thanks in advance,

jscript

$(document).ready(function () {
            $('#add').click(function () {
                InsertFields();
            });
            //insert first row
            function InsertFields() {
                $("<div class='additionalrow'><select name='condition'><option value='AND'>AND</option><option value='OR'>OR</option></select><input type='text' name='fieldname' id='fieldName' size='20' /><select name='operator'class='operClass'><option id='opt1' value='CONTAINS'>Contains</option><option id='opt2' value='DOES NOT CONTAIN'>Does Not Contain</option><option id='opt3' value='LIKE'>Like</option><option id='opt4' value='BETWEEN'>Between</option></select><input type='text' name='fieldValue1' id='fieldvalue1' value='' size='20' /> <input type='button' id='newAdd' value='Add' /> <input type='button' id='btnRemove' value='Remove' /></div>").appendTo('#queryFields');
            }
            //add additional row 
            //used second funciton to reset bindings
            $('#newAdd').live('click', function () {
                $("<div class='additionalrow'><select name='condition'><option value='AND'>AND</option><option value='OR'>OR</option></select><input type='text' name='fieldname' id='fieldName' size='20' /><select id='newOperator' name='operator' class='operClass'><option id='opt1' value='CONTAINS'>Contains</option><option id='opt2' value='DOES NOT CONTAIN'>Does Not Contain</option><option id='opt3' value='LIKE'>Like</option><option id='opt4' value='BETWEEN'>Between</option></select><input type='text' name='fieldValue1' id='fieldvalue1' value='' size='20' /> <input type='button' id='newAdd' value='Add' /> <input type='button' id='btnRemove' value='Remove' /></div>").appendTo('#queryFields');
            });
            //remove row
            $('#btnRemove').live('click', function () {
                $(this).parent().remove();
            });

            $('.operClass').change(function () {
                var foo = $('.operClass option:selected').val();
                alert(foo); 
            });

            $('select').live('change', '.operClass', function () {
                var sb = $(this, '.operClass option:selected').val();
                var ci = $(this, '.operClass');
                insertFromField(sb, ci);
            });
            //insert field after between option or remove it if it exists
            function insertFromField(param1, param2, param3) {

                if (param1 == "BETWEEN") {
                    $("<input type='text' name='fieldValue1' id='fieldvalue1' value='' size='20' />").insertAfter(param2);    
                }
                else {
                //need to test count of existing input fields for the current row here if n > 1 remove the second field else do nothing.
                    $(param2).next().remove();
                }
            }
        });  

html

<div id="queryFields">
            <select name="condition">
                <option value="AND">AND</option>
                <option value="OR">OR</option>
            </select>
            <input type="text" name="fieldname" id="fieldName" size="20" />
            <select  name="operator">
                <option id="opt1" value="CONTAINS">Contains</option>
                <option id="opt2" value="DOES NOT CONTAIN">Does Not Contain</option>
                <option id="opt3" value="LIKE">Like</option>
                <option id="opt4" value="BETWEEN">Between</option>
            </select>
            <input type="text" name="fieldValue1" id="fieldvalue1" value="" size="20" />
            <input type="button" id="add" value="Add" /> 
        </div>
  • 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-26T20:27:56+00:00Added an answer on May 26, 2026 at 8:27 pm

    You can do this

    var $selector = $(this); /* Assuming the selector is `this` */
    var count = $selector.siblings("input:text").length;
    

    No extra classes needed.

    If you only want to match text inputs AFTER the select, you can use:

    $selector.nextAll("input:text").length;
    

    This won’t match the first text input before each select.

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

Sidebar

Related Questions

I have an ASP.NET page that has three div s within the only form
I have a form that contains field sets and has the ability to add
I have this form: <form name=customize> Only show results within <select name=distance id=slct_distance> <option>25</option>
Within a form I have a button that launches a cfwindow, then presents a
Within a form I have a user control for each field being returned. The
I have a form that's ajaxed in, and within that form it generates new
I have a form within an ASP.NET MVC application and I'm trying to submit
I have a complex input form within a PHP based web application. To structure
I have a need to close a parent form from within child form from
I have a list within Sharepoint, using a custom new form I have added

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.