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

The Archive Base Latest Questions

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

currently I have a method of showing / hiding a div based on a

  • 0

currently I have a method of showing / hiding a div based on a form checkbox field as per below. What I do want however is to not use a form to show hide rather just call the show / hide function based on a simple on a link . I hope this makes sense what I am attempting to do. Any help /advice would be really valued!

<!-- Show hide-->
<script language="JavaScript">
function showhidefield()
{
if (document.goform.areas.checked)
{
document.getElementById("areaone").style.display = "block";
document.getElementById("areatwo").style.display = "none";
}
else
{
document.getElementById("areaone").style.display = "none";
document.getElementById("areatwo").style.display = "block";

}
}
</script>

<form name="goform" id="goform" action="xxxx" method="post" enctype="multipart/form-data">

<label><input name="areas" type="checkbox" onclick="showhidefield()" value="1"> Yes </label>

</form>

<div id="areaone" style="display:none;">
Area One
</div><!-- / Hideable area -->


<div id="areatwo" style="display:block;">
Area two
</div>

Changing the above so that rather than using a form checkbox to showhide, have a toggle effect based on event e.g.

<a href="xxx">Show Areaone / Hide Areatwo</a>

<a href="xxx">Show Areatwo / Hide Areaone</a>
  • 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-10T19:12:28+00:00Added an answer on June 10, 2026 at 7:12 pm

    General Approach

    The general approach is to use the onclick property of link tags. You can set this directly on the tag like this:

    <a onclick="showhidefield()" href="javascript:void(0);">Show/Hide</a>
    

    Example 1

    Here’s a full working example:

    <!DOCTYPE html>
    <html>
      <head></head>
      <body>
        <div id="areaone" style="display:none;">
          Area one
        </div>
        <div id="areatwo" style="display:block;">
          Area two
        </div>
        <script type='text/javascript'>
          function showOneHideTwo(){
              document.getElementById("areaone").style.display = "block";
              document.getElementById("areatwo").style.display = "none";
          }
    
          function showTwoHideOne(){
              document.getElementById("areaone").style.display = "none";
              document.getElementById("areatwo").style.display = "block";
          }      
        </script>
        <a onclick="showOneHideTwo()" href="javascript:void(0);">Show one / Hide two</a>
        <a onclick="showTwoHideOne()" href="javascript:void(0);">Show two / Hide one</a>
      </body>
    </html>
    

    Example 2 (Better!)

    However, for a variety of reasons, it is preferable, if slightly less intuitive, to use javascript to set the onclick property instead of adding it to the html directly. Here is a better full working example:

    <!DOCTYPE html>
    <html>
      <head></head>
      <body>
        <div id="areaone" style="display:none;">
          Area one
        </div>
        <div id="areatwo" style="display:block;">
          Area two
        </div>
        <a id='showOneLink' href=''>Show one / Hide two</a>
        <a id='showTwoLink' href=''>Show two / Hide one</a>
        <script type='text/javascript'> <!-- This allows for better placement of the script as well... -->
          //Same functions as before
          function showOneHideTwo(){
              document.getElementById("areaone").style.display = "block";
              document.getElementById("areatwo").style.display = "none";
          }
    
          function showTwoHideOne(){
              document.getElementById("areaone").style.display = "none";
              document.getElementById("areatwo").style.display = "block";
          }
    
          //this time, we set the onclick here
          //this is better form- it keeps the content (html) and the scripting (javascript) seperate
          document.getElementById("showOneLink").onclick = function(){showOneHideTwo(); return false;}
          document.getElementById("showTwoLink").onclick = function(){showTwoHideOne(); return false;}
        </script> 
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i currently have a method that checks what is around the centre item in
I currently have this method: -(void)seperateGuides { DLog(GetGuideListCount: %i, [[appDelegate getGuideList] count]); columnOneArray =
I currently have this working but it requires me to have a static method
I currently have the following controller method in a Rails app: def index @entries
Hey, I currently have a Currency Format method: private string FormatCurrency(double moneyIn) { CultureInfo
Currently I have created a ABCFactory class that has a single method creating ABC
I have a method in Java that concatenates 2 Strings. It currently works correctly,
All, I have a method that is currently used to invoke DLLs of return
currently in my update controller method I have: @group.attributes = { :title => params[:group][:title],
I am currently working on MVC4 SinglePage Application. I have a Web Api method

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.