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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:31:03+00:00 2026-06-07T13:31:03+00:00

I have a question about removing all elements after the current one. here’s the

  • 0

I have a question about removing all elements after the current one.

here’s the scenario:

I have a location tree that my users need to wade through to get to a specific value. I have a SELECT that loads the top-level location via ajax. The data has more granular values in order to narrow the selection down, so I add a new SELECT depending on what the user chose. When the user gets to the end of available options for the data, I stop adding SELECTs and grab the value of the last one, which is what I’m after.

The way I coded this is to start with one SELECT which has the top-level location ID hard-wired in, then have an ‘onchange’ event handler which goes out to my database and grabs the children for that selection, then creates the new select within the current TD.

This goes on until no children are returned for the last choice. At that point, I can get the ID of this final location.

This works great UNTIL the user decides to change something one or two selects “upstream”.

Here’s an illustration of what a user that has gotten down the location tree might have (these are SELECTs in code):

USA -> Ohio -> Cuyahoga -> Cleveland -> District 1

if ‘District 1’ was the last available item in this chain of locations, I can get it using $(‘#locations select:last’).val(). Wunderbar.

What doesn’t work so well is if the user decides, “Hmm, no it’s not Cuyahoga I’m after, but Stow”, and changes the third select option. What I need to do is remove all selects AFTER the select that has ‘Cuyahoga’, since I now have to go fetch any further data for “Stow”. Any selects after the prior choice are no longer valid.

The select that is being manipulated passes itself in the onchange event, so that I have the current element. I’ve tried $(elem).after().remove(), but that doesn’t work.

Any ideas on how I can remove all SELECTs after the current one?

Thanks!

The structure of the doc looks something like this:

<table border id="loctable">
  <tr><th>Location:</th><td><select id="loc0" onchange="return UpdateLocationSelect(this);">
    <option>choose..</option>
    <option value="3">USA</option>
    </select>
  </td>
  </tr>

[snip]

function UpdateLocationSelect(elem) {
    // load sub locations for PPID given. IN this case, locations under USA. add options to elem
    // Also, erase any selects after this one, in case the user has "backed up" his selection

    $(elem).next().remove();  // Help needed here!! how to remove any SELECTs after this one??

    $.ajax({
        url: "api.php",
        dataType: "json",
        data: { cmd: "sublocs", "pid": elem.value },
        async: false,
        success: function( data, textStatus ) {
            // results
            if( $(data).length ) {
                $('#loctable td').append( "<select onchange='return UpdateLocationSelect(this);'><option>choose..</option></select>");
                $.each( data, function( key, val ){
                    $('#loctable select:last').append( '<option value="'+key+'">'+val+'</option>' );
                });
            }
            else
            {
                // we've hit the end of this location branch. Alert to check val is right
                alert( "LocID: " + $('#loctable select:last').val() );
            }
        },
      });
      return false;
    }
  • 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-07T13:31:04+00:00Added an answer on June 7, 2026 at 1:31 pm
    $(elem).nextAll().remove();
    

    If you need to specify a selector, you can do that using the same method.

    $(elem).nextAll('select.some-class').remove();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about removing non-alphanumeric characters from a list in R. I
I have question about XSLT1.0. The task is to write out in HTML all
I use a cluster of about 30 machines that have all recently been reconfigured
I have a rather specific question about how to exclude items of one list
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) 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.