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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:36:14+00:00 2026-06-08T21:36:14+00:00

I have a very basic hide/show div function set up for when people click

  • 0

I have a very basic hide/show div function set up for when people click a certain radio button. In one of the hidden divs I need to create a form however when I add input fields to the hidden div my function stops working.

<div id="tabs">
<div id="nav">
  <input type="radio" name="primary_contact_director" value="Yes" class="div1">Yes</input>
    <input type="radio" name="primary_contact_director" value="No" class="div2">No</input>
</div>

<div id="div1" class="tab">
  <p>this is div 1</p>
</div>

<div id="div2" class="tab">
  <p>this is div 2</p>
</div>
</div>

<script type="text/javascript" charset="utf-8">
(function(){
  var tabs =document.getElementById('tabs');
  var nav = tabs.getElementsByTagName('input');

  /* 
  * Hide all tabs
  */
  function hideTabs(){
    var tab = tabs.getElementsByTagName('div');
    for(var i=0;i<=nav.length;i++){
      if(tab[i].className == 'tab'){
        tab[i].className = tab[i].className + ' hide';
      }
    }
  }

  /*
  * Show the clicked tab
  */
  function showTab(tab){
    document.getElementById(tab).className = 'tab'
  }

  hideTabs(); /* hide tabs on load */

  /* 
  * Add click events
  */
  for(var i=0;i<nav.length;i++){
    nav[i].onclick = function(){
      hideTabs();
      showTab(this.className);
    }
  }
})();

This code works however when I add

<label class="title">First Name:</label>
    <input type="text" name="first_name" class="form">
<label class="title">Last Name:</label>
    <input type="text" name="last_name" class="form">
<label class="title">Business Address:</label>
    <span class="instructions">Please enter a physical address. P.O. Boxes are not acceptable for filing.<br>
    If your business is run out of your home, please list that address.</span><br>
    <input type="text" name="business_address" class="form">
<label class="title">City:</label>
    <input type="text" name="business_city" class="form">
<label class="title">State</label>
    <select name="business_state">
        <option value="California">California</option>
    </select>
<label class="title">Zip Code:</label>
    <input type="text" name="business_zip" class="form">
<label class="title">Business Phone Number:</label>
    <input type="text" name="business_phone" class="form"><br>

to my div2 it stops working.

Hopefully this is a clear explanation. Any help is always appreciated!

  • 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-08T21:36:17+00:00Added an answer on June 8, 2026 at 9:36 pm

    In your hideTabs() function, you’ve got two typos.

    First, you’re iterating through the tab[] array, but you’re checking it against the length of the nav[] array. This works because you have the same number of elements in your first example, but that’s just a coincidence. If you evaluate it against the tab[] array’s length, it will work better. The other problem you have is that your for loop ends at greater-than-or-equal-to length. THe problem is that arrays start counting at zero, so if the length is 3, the items on the list are tab[0], tab[1], and tab[2]. your code was trying to set something for tab[3], which didn’t exist.

    Here’s the working code:

    /* 
    * Hide all tabs
    */
    function hideTabs(){
      var tab = tabs.getElementsByTagName('div');
      for(var i=0;i<tab.length;i++){
        if(tab[i].className == 'tab'){
          tab[i].className = tab[i].className + ' hide';
        }
      }
    }
    

    In the future, you should look into using the javascript console in Chrome (or any other browser) to check for errors if your scripts stop working—usually there’s an error that that will give you hints as to what’s happening.

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

Sidebar

Related Questions

I have this very basic tabbed block: $('.tabbed-section .panel').hide(); $('.tabbed-section .panel:first').show(); $('.tabbed-section .tabs li:first').addClass('active');
I have a very basic mysql table called memberships, that tracks which people belong
I have very basic class: class Customer { protected $id; protected $customer; public function
I have very basic question regarding return value of a function, and checking the
I have a very basic API in my app which also has an index
I have a very basic windows forms app, working in C#, and I was
I have a very basic app with two ignition-remoteimageviews (RIV) in them. The app
I have some very basic semaphore code that works great on Linux, but cannot
I have a very basic doubt regarding the method that gets executed when app
I have a very basic knowledge of the web programming, and I couldn't figure

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.