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

  • Home
  • SEARCH
  • 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 8047937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:16:10+00:00 2026-06-05T06:16:10+00:00

var filters_used = new Array(); $(‘#filter-text’).keyup(function(k) { $(‘#error’).html(”); if (k.keyCode == 13) { $(‘#add-filter’).click();

  • 0
var filters_used = new Array();
$('#filter-text').keyup(function(k) {
    $('#error').html('');
    if (k.keyCode == 13) {
        $('#add-filter').click();
    }
});

function reg_remove() {
    $('.remove-filter').click(function() {
        console.debug("remove-filter.click()");
        var col = $(this).children('td:nth-child(2)').html();
        var index = $.inArray(col, filters_used);
        filters_used.splice(index, 1);
        $(this).parents('.filter').remove();
        return false;
    });
}

function check_value() {
    var flag = true;
    var value = $('#filter-text').val();
    var col = $('#filter-type').val();
    var reg = /[^0-9a-zA-Z\s\-]/;
    if (value.match(reg) || value.trim() === "") {
        flag = false;
        $('#error').html('Only letters, numbers, spaces, and dashes (-) are allowed.');
    } else if ($.inArray(col, filters_used) >= 0) {
        flag = false;
        $('#error').html('That column is already being filtered.');
    }
    return flag;
}
$('#add-filter').click(function() {
    if (check_value()) {
        var value = $('#filter-text').val();
        var col = $('#filter-type').val();
        $('#filter-text').val('');
        appendstr = '<tr class="filter"><td>' + value + '</td><td>' + col + '</td><td>' + '<a href="" class="remove-filter">Remove</a></td></tr>';
        $('#filter-form').after(appendstr);
        filters_used.push(col);
        reg_remove();
        //queryDB();
    }
});

function get_filters() {

}?

Link to a fiddle containing my code
I am trying to let users create a list of filters, essentially. Adding them seems to work fine, however the remove() function only works properly when there is only one filter item. If you create a first, then click remove on the bottom item, the onclick() function for that item is called twice, and I can’t for the life of me figure out why.

  • 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-05T06:16:13+00:00Added an answer on June 5, 2026 at 6:16 am

    Can’t see the fiddle running, but from the code you might want to change the

    $('#add-filter').click(function() {
    

    to

    $('#add-filter').click(function(e) {
        e.preventDefault()
    

    (same with the other click)

    EDIT:
    Oh, now I can see it running. The actual problem it seems to me is that when you add a ‘remove’ link, you do a rebinding of click for .remove-filter (which includes the already created ones).
    Instead what you can do is use .on only once, and it applies to all the elements you have plus whatever new elements you create. Something like…

    $('table').on("click", ".remove-filter", function() {
    ...
    

    do this once in the document.ready and that should do it (remove the call to reg_remove after adding a ‘remove’ link)

    P.D. .on works on jquery 1.7 and later, if you use an earlier version, you’d use .live or .delegate to achieve that

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

Sidebar

Related Questions

Revised Code jQuery(function($) { $(#filter).keyup(function () { var filter = $(this).val(), count = 0;
Array.prototype.testi = function() {console.log('hep');} var b = new Array(); b.push(1, 5, 'b', 'c'); for
I want to do something like $('a.filter-link').click(function(e) { e.preventDefault(); var that = $(this), categoryId
$.get($(this).attr('id'), function(data){ var qp_post = $(data).filter('title'); alert(qp_post); }); This fetches the content fine however
I find myself doing this repeatedy. $jq(button).filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/);
public static void MyFunction(MyErrorClass err) { var query = from filter in DataContext.ErrorFilters select
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
I have a javascript function which should filter a specific row from a shape
I am new to JavaScript and jQuery, but have used HTML and CSS before.
I have a HTML list of about 500 items and a filter box above

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.