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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:33:14+00:00 2026-05-15T01:33:14+00:00

I have been working on a Java project in which the reports will be

  • 0

I have been working on a Java project in which the reports will be generated in HTML, so I am implementing methods for creating these reports. One important functionality is to be able to have as much info as possible in the tables, but still not clutter too much. In other words the details should be available if the user wishes to take a look at them but not necessarily visible by default.

I have done some searching and testing and found an interesting template for hiding/showing content with the use of CSS and javascript, the problem is that when I try the resultant html page the scripts dont work. I am not sure if it’s due a problem in Java or in the javascript itself. I have compared the html code that java produces to the source where I found the template, they seem to match pretty well.

Below are bits of my java code that generates the javascript and the content, i would greatly appreciate if anyone can point out the possible reasons for this problem:

//goes to head

private void addShowHideScript() throws IOException{
    StringBuilder sb = new StringBuilder();
    sb.append("<script type=\"text/javascript\" language=\"JavaScript\">\n");
    sb.append("<!--function HideContent(d) {\n");
    sb.append("document.getElementById(d).style.display=\"none\";}\n");

    sb.append("function ShowContent(d) {\n");
    sb.append("document.getElementById(d).style.display=\"block\";}\n");

    sb.append("function ReverseDisplay(d) {\n");
    sb.append("if(document.getElementById(d).style.display==\"none\")\n");
    sb.append("{ document.getElementById(d).style.display=\"block\"; }\n");
    sb.append("else { document.getElementById(d).style.display=\"none\"; }\n}\n");
    sb.append("//--></script>\n");
    out.write(sb.toString());
    out.newLine();
}

// body

    private String linkShowHideContent(String pathname, String divname){
    StringBuilder sb = new StringBuilder();
    sb.append("<a href=\"javascript:ReverseDisplay('");
    sb.append(divname);
    sb.append("')\">");
    sb.append(pathname);
    sb.append("</a>");
    return sb.toString();

}

// content

    out.write(linkShowHideContent("hidden content", "ex"));
    out.write("<div id=\"ex\" style=\"display:block;\">");
    out.write("<p>Content goes here.</p></div>");

Update // a chunk of the html code from the page that reflects the problem

<html><head><style type="text/css">

#table {font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; width:75%;border-collapse:collapse;}
#table td, #table th {font-size:1em;border:1px solid #98bf21;padding:5px 8px 5px 10px;}
#table th {font-size:1.2em;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#fff;}
#table tr.alt td {color:#000;background-color:#EAF2D3;}
</style></head><body>
<h2> QUERY RESULTS </h2>
<script type="text/javascript" language="javascript">
<!--function HideContent(d) {
document.getElementById(d).style.display="none";}
function ShowContent(d) {
document.getElementById(d).style.display="block";}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display=="none")
{ document.getElementById(d).style.display="block"; }
else { document.getElementById(d).style.display="none"; }
}
//--></script>
<a href="javascript:ReverseDisplay('ex')">hidden content</a>
<div id="ex" style="display:block;">
<p>Content goes here.</p></div>
  • 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-15T01:33:15+00:00Added an answer on May 15, 2026 at 1:33 am

    I executed your methods and this resulted (formatting not included :D):

    <script type="text/javascript" language="JavaScript">
    <!--
    function HideContent(d) {
      document.getElementById(d).style.display="none";
    }
    
    function ShowContent(d) {
      document.getElementById(d).style.display="block";
    }
    
    function ReverseDisplay(d) {
      if(document.getElementById(d).style.display=="none") { 
        document.getElementById(d).style.display="block"; }
      else { 
        document.getElementById(d).style.display="none"; 
      }
    }
    //-->
    </script>
    
    <a href="javascript:ReverseDisplay('ex')">hidden content</a>
    <div id="ex" style="display:block;">
      <p>Content goes here.</p>
    </div>
    

    It works just fine on IE 8 and Firefox 3.6.

    Do you have JavaScript disabled in your browser or some security restrictions that cut your scripts from running?

    EDIT: Based on the code you posted, the problem seems to be this:

    <!--function HideContent(d) {
    

    If you write it like this it works:

    <!--
    function HideContent(d) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Casper is basically a storage container for Linux systems which… May 15, 2026 at 2:34 pm
  • Editorial Team
    Editorial Team added an answer Find the GUID of mouse and disable the mouse using… May 15, 2026 at 2:34 pm
  • Editorial Team
    Editorial Team added an answer It's helpful to think of a JTree as a view… May 15, 2026 at 2:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.