[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Show/Hide table, rows and columns via checkbox and radio button

Posted on 2007-10-15
4
Medium Priority
?
1,234 Views
Last Modified: 2012-06-21
I'm having problems making this script work. Basically, I need to show a table when the checkbox is checked, and, depending on what radio button is selected from the second table, show or hide a column. Any ideas? Thanks!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html><head>
<script language="JavaScript" type="text/javascript">
function checkTab(theTab)
{
  f=document.setup;
  if(f.recurrence_check.checked==true) {
    document.getElementByID("recurrence_table").style.display="";
  } else {
    document.getElementByID("recurrence_table").style.display="none";
  }
  if(f.recurrence_type[0].checked) {
    document.getElementById("daily").style.display="";
    document.getElementById("weekly").style.display="none";
    document.getElementById("recurrence_stop").style.display="";
  }
  if(f.recurrence_type[1].checked) {
    document.getElementById("daily").style.display="none";
    document.getElementById("weekly").style.display="";
    document.getElementById("recurrence_stop").style.display="";
  }
}
</script>
</head>

<body>
<table onClick="checkTab(this)" border=1>
<tr><th rowspan=2>Recurrence</th>
<td><input type="checkbox" id="recurrence_check" name="recurrence_check" value="1">Add Recurrence</td>
<tr><td>
      <table border="1" id="recurrence_table" style="none">
      <tr><td>
      <input type="radio" name="recurrence_type" value="1" >Daily<br>
      <input type="radio" name="recurrence_type" value="2" >Weekly<br>
      </td>

      <td id="daily" style="display:none">
      <input type="radio" name="daily" value="1" >Every day<br>
      <input type="radio" name="daily" value="2">Every weekday<br>
      </td>

      <td id=weekly style="display:none">
      <input type="checkbox" name="weekly[]" value="1" />Monday <br />
      <input type="checkbox" name="weekly[]" value="2" />Tuesday <br />
      <input type="checkbox" name="weekly[]" value="3" />Wednesday <br />
      <input type="checkbox" name="weekly[]" value="4" />Thursday <br />
      <input type="checkbox" name="weekly[]" value="5" />Friday <br />
      </td>

      <td id="recurrence_stop" style="display:none">Date to stop recurrence:<br />
      <input type="textbox" name="recurrence_stop" />
      </td></tr></table>
</td></tr></table>
0
Comment
Question by:horalia
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 20080383
horalia,

I think you forgot a form tag, and made a casing typo on getElementByID (should be getElementById).
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html><head>
<script language="JavaScript" type="text/javascript">
function checkTab(theTab)
{
  f = document.forms['setup'];
  if(f.recurrence_check.checked==true) {
    document.getElementById("recurrence_table").style.display="";
  } else {
    document.getElementById("recurrence_table").style.display="none";
  }
  if(f.recurrence_type[0].checked) {
    document.getElementById("daily").style.display="";
    document.getElementById("weekly").style.display="none";
    document.getElementById("recurrence_stop").style.display="";
  }
  if(f.recurrence_type[1].checked) {
    document.getElementById("daily").style.display="none";
    document.getElementById("weekly").style.display="";
    document.getElementById("recurrence_stop").style.display="";
  }
}
</script>
</head>

<body>
<form name="setup">
<table onClick="checkTab(this)" border=1>
<tr><th rowspan=2>Recurrence</th>
<td><input type="checkbox" id="recurrence_check" name="recurrence_check" value="1">Add Recurrence</td>
<tr><td>
      <table border="1" id="recurrence_table" style="none">
      <tr><td>
      <input type="radio" name="recurrence_type" value="1" >Daily<br>
      <input type="radio" name="recurrence_type" value="2" >Weekly<br>
      </td>

      <td id="daily" style="display:none">
      <input type="radio" name="daily" value="1" >Every day<br>
      <input type="radio" name="daily" value="2">Every weekday<br>
      </td>

      <td id=weekly style="display:none">
      <input type="checkbox" name="weekly[]" value="1" />Monday

      <input type="checkbox" name="weekly[]" value="2" />Tuesday

      <input type="checkbox" name="weekly[]" value="3" />Wednesday

      <input type="checkbox" name="weekly[]" value="4" />Thursday

      <input type="checkbox" name="weekly[]" value="5" />Friday

      </td>

      <td id="recurrence_stop" style="display:none">Date to stop recurrence:

      <input type="textbox" name="recurrence_stop" />
      </td></tr></table>
</td></tr></table>
</form>

Kind regards,

-r-
0
 

Author Comment

by:horalia
ID: 20080492
Thank you for the quick response Roonan. You are right, adding the form tag fixes the issue, but not completely. When I load the page, the recurrence table still shows. It is hidden only after I check and then uncheck the checkbox.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 20080503
That's because style="none" should be style="display:none" I suppose.

-r-
0
 

Author Comment

by:horalia
ID: 20080536
You supposed right! Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question