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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:17:54+00:00 2026-06-12T19:17:54+00:00

I am working with a page that has multiple divs that toggle. This function

  • 0

I am working with a page that has multiple divs that toggle. This function works. A search function was added and this works too.

The problem with the page as it exists currently: The search bar was placed on the “default” div and the results load below the bar into another div that is invisible when empty. The results div is inside this first default div. If you toggle to another div, you lose the default div and can’t get back to it.

For this reason, I moved the search bar to the left navigation where the other toggle links are situated. I also moved the search results div out of the default div to “stand on its own.”

What I am trying to do: Make the search button show the div with the results as well as find the results. Basically, to integrate the search function into the array/toggle function. The search function is in one .js file and the toggle function is in a different .js file.

I keep thinking there must be a way to get “onclick” to call from both .js files so that I don’t have to do a bunch of extra work combining the two functions that already exist and work separately. I am a Javascript newbie learning by examples and haven’t been able to figure this out. I have never seen a working example of this and my searches haven’t produced one.

I would be very grateful for any help. Hope I explained the problem adequately.

Edit: Here is the code I already have for the toggle function.

var ids=new Array('a','b','c',[and so on--search results not added here yet]);

function switchid(id_array){
    hideallids();
    for( var i=0, limit=id_array.length; i < limit; ++i)
        showdiv(id_array[i]);
}

function hideallids(){
    for (var i=0;i<ids.length;i++){
        hidediv(ids[i]);
    }
}

function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id) {//safe function to show an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}

function initialize(){
    var t = gup("target");
    if( t )
    {
        switchid([t]);
    }
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null ){
      return "";
  } else {
      return results[1];
  }
}

Thanks in advance!

  • 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-12T19:17:55+00:00Added an answer on June 12, 2026 at 7:17 pm

    When your toggle function code is loaded, the functions are declared in the Global scope. When you search functions are loaded, they are also in the Global scope. Since they are in the same scope, even though it’s a different file, the toggle functions can be used by your search function, if you include the file with the search function after the file with the toggle function.

    TL;DR

    function search(...) {
        // do your search stuff
        // when you get a result ID, toggle it from here
        hideallids();
        showdiv(id);
    }
    

    I seriously recommend you use meaningful names, objects as namespaces to organize your code, and CamelCase or underscores to mark word boundaries in identifiers. For example:

    window.ZESearch = {
        'initialize' : function() { ... },
        'search': function() {
            // Find the node with the desired result
            ZESearch.showResult(id);
        },
        'hideAllResults': function() { ... },
        'hideResult' : function(id) { ... },
        'showResult' : function(id) { ... },
        ...
    };
    ZESearch.initialize();
    

    Since you’re just learning, I’ve avoided the complexity of the this keyword, presented a simple way to create an object to keep your code organized but added your object to window so you can get it from anywhere in your code.

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

Sidebar

Related Questions

I'm working on a page that has three divs next to each other, each
I'm working with a page that has multiple <form> tags in it. One of
I'm working on a web page that has multiple pages to display. <div class='tab'>
Im working on a site that currently has multiple H1 tags per page. What
I'm working on a page that has some ads on it. One of them
I am currently working on a page that has a date picker for one
I'm working on a PHP dynamic web page that has a <textarea> element that
I am working on a web page that has a large number of tables.
I am working with php and want to have a page that has a
The ASP.net page I am currently working on has a drop down list that

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.