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

The Archive Base Latest Questions

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

I am having to use jQuery I did not write, it was included in

  • 0

I am having to use jQuery I did not write, it was included in a template.

There is a function that does a ‘guess type,’ and uses the main navigation as the data to search against. As you type, pages within the site come up in the dropdown.

I need customer names from a database to dropdown, but I can’t seem to get the function to work.

function searchInNav(s)
    {
        // Split keywords
        var keywords = s.toLowerCase().split(/\s+/);
        var nbKeywords = keywords.length;

        // Search links
        //var links = $('nav a'); // original
          var links = [];

        // LOAD CUSTOMERS AND EVENTS
        $.post('includes/ajax/global.php', { list: 'search', text: keywords },
            function(data){
                alert(data);
                links.push($(data));
            },
            "html"
        );

        var matches = [];
        links.each(function(i)
        {
            var text = $(this).text().toLowerCase();
            var textMatch = true;
            for (var i = 0; i < nbKeywords; ++i)
            {
                if (text.indexOf(keywords[i]) == -1)
                {
                    textMatch = false;
                    break;
                }
            }

            if (textMatch)
            {
                // All keywords found
                matches.push(this);
            }
        });

        // Build results list
        var nbMatches = matches.length;
        if (nbMatches > 0)
        {
            var output = '<p class="results-count"><strong>'+nbMatches+'</strong> match'+((nbMatches > 1) ? 'es' : '')+'</p>';
            output += '<ul class="small-files-list icon-html">';

            for (var m = 0; m < nbMatches; ++m)
            {
                // Text with highlighted keywords
                var link = $(matches[m]);
                var text = link.text();
                var path = [text];
                for (var i = 0; i < nbKeywords; ++i)
                {
                    text = text.replace(new RegExp('('+keywords[i]+')', 'gi'), '<strong>$1</strong>');
                }

                // Path
                var parent = link;
                while ((parent = parent.parent().parent().prev('a')) && parent.length > 0)
                {
                    path.push(parent.text());
                }

                output += '<li><a href="'+matches[m].href+'">'+text+'<br><small>'+path.reverse().join(' > ')+'</small></a></li>';
            }

            return output+'</ul>';
        }
        else
        {
            return '<p class="results-count">'+settings.messageNoMatches+'</p>';
        }
    };

I keep getting errors with the links.each line, saying Object has not method each.

What do I need to fix?

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-05-26T20:57:50+00:00Added an answer on May 26, 2026 at 8:57 pm

    This is your problem:

    //var links = $('nav a'); // original
    

    $(‘nav a’) makes a jQuery object of all a tags in nav. yours is just an array.

    You need to modify that whole loop to handle it as an array and not a jquery object…

        for(var i = 0; i < links.length; i ++)
        {
            var text = links[i].toLowerCase();
            var textMatch = true;
            for (var n = 0; n < nbKeywords; ++n)
            {
                if (text.indexOf(keywords[n]) == -n)
                {
                    textMatch = false;
                    break;
                }
            }
    
            if (textMatch)
            {
                // All keywords found
                matches.push(links[i]);
            }
        });
    

    But I can’t guearntee this modification above. The general concept is that you changed it from a jquery object to an array so you have to modify the loop accordingly.

    Also, what is this:

    links.push($(data));
    

    Is data returning an expected dom id? like #some_div? Otherwise that $() makes no sense. It should just be data.

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

Sidebar

Related Questions

Having discovered that IE does not handle javascript onmouseout , I'm determined to use
I am having a problem trying to use the prependTo() function in jQuery... for
I'm having a little problem. I'm trying to use Jquery load() function to load
My buddy at work told me that you could use jQuery to write a
I originally used JQuery for this project, but now I'm having to use Prototype,
i am having the strangest problem with jQuery animate when i use marginTop it
Is there a way to use the HAVING clause in some other way without
I want to make a form that will use jquery to submit a list
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
Hi I am having an issue where i am trying to use JQuery to

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.