Solved

Radio Buttons not working with Show/Hide Div

Posted on 2009-05-11
2
1,410 Views
Last Modified: 2012-05-07
Hello,

I have a problem with radio buttons and divs that I am show/hide upon click of rdio button. I have a set of radio buttons and two divs, one is shown and one is hidden. Upon clicking radio buttons, they show and hide the proper divs and display the proper checked function of the radio button. If you go back and click the original radio button, the divs change, but the checked state of the radio button does not display properly...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Attach a Document</title>

<script type="text/javascript">

	

 

function hide(id){

	document.getElementById(id).style.display='none';

}

function show(id){

	document.getElementById(id).style.display='';//'block'

}</script>
 

<style type="text/css">

<!--

#pageHeader { color: #FF9900; height: 18px; padding-top: 3px; padding-bottom: 3px; margin-top: 5px; margin-left: 5px; vertical-align: middle; text-align:left; font: bold 16px Arial, Helvetica, sans-serif; margin-bottom: 20px; }

#container ul { list-style: none; padding: 3px; margin: 0px; }

#upload table { margin-left: auto; margin-right: auto; width: 700px; }

#container { font-family: Arial, Helvetica, sans-serif; width: 900px; }

#options { width: 610px; margin-right: auto; margin-left: auto; font-weight: bold; }

#upload { width: 700px; margin-right: auto; margin-left: auto; font-weight: bold; }

#container li { display: inline; margin-right: 25px; }

/*#textfield { font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; height: 15px; border: 1px solid #6699CC; }*/

.dataHeader { font-weight: bold; color: #000000; line-height: 22px; text-indent: 2px; vertical-align: middle; text-align: left; background-color: #C3DEF9; padding: 1px; }

#upload table { font-weight: normal; }
 

-->

</style>

<link href="../HFPM_hybrid.css" rel="stylesheet" type="text/css" />

</head>
 

<body>
 

<div id="container">

<div id="pageHeader">Attach a Document</div>
 
 

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

  <div id="options">

    <div style="margin-left:auto; margin-right:auto; width:610px; margin-bottom:20px;" class="instructions" >

  <ul>

  <li>  <input name="radio" type="radio" id="radio" checked="checked" onclick="hide('upload');show('options')" />

  Browse your  computer and upload a file</li>

  <li>   -OR- </li>

  <li>  <input type="radio" name="radio" id="radio2" onclick="hide('options');show('upload')" />

  Select a file from your document library </li>

  </ul>

  </div>

  <table cellpadding="1" cellspacing="1" style="width:450px; margin-left:10px;">

  <tr>

    <td>File Location</td>

    <td><input type="file" name="fileField" id="fileField" /></td>

  </tr>

  <tr>

    <td>Document Type</td>

    <td><select name="select" id="select" style="width:200px;">

      <option>Patient Form</option>

    </select>

    </td>

  </tr>

  <tr>

    <td>Title</td>

    <td><input name="textfield2" type="text" class="formfield" id="textfield2" style="width:250px;" value="Family History Form" /></td>

  </tr>

  <tr>

    <td>Document Date</td>

    <td><input name="textfield3" type="text" class="formfield" id="textfield3" value="04/28/2009" />

      <img src="../images/icon_calendar.png" width="18" height="16" /></td>

  </tr>

  <tr>

    <td>Review Required</td>

    <td><select name="select2" id="select2" style="width:200px;">

      <option>NO REVIEW REQUIRED</option>

      <option selected="selected">JOHNSON, JACK</option>

      <option>SMITH, MIKE</option>

    </select>

    </td>

  </tr>

</table>

<div style="background-color:#e5e5e5; margin-top:25px;">

    <div style="margin-left:auto; margin-right:auto; width:150px; padding-top:10px; padding-bottom:10px;">

    <input name="button3" type="button" class="frmButton" id="button3" value="Upload" />

    <input name="button4" type="button" class="frmButton" id="button4" value="Cancel" onclick="javascript:window.close();" />

    </div>

  </div>

</div>
 

<div id="upload" style="display:none;">

  <div style="margin-left:auto; margin-right:auto; width:610px; margin-bottom:20px;" class="instructions" >

  <ul>

  <li>  

    <input type="radio" name="radio2" id="radio3" onclick="hide('upload');show('options')" />

    Browse your  computer and upload a file</li>

  <li>   -OR- </li>

  <li>

<input name="radio2" type="radio" id="radio4" checked="checked" onclick="hide('options');show('upload')" />    

Select a file from your document library </li>

  </ul>

  </div>

  <table cellspacing="1" cellpadding="1">

  <tr>

    <td colspan="7" style="text-align:right"><strong>Filter by:</strong>      <select name="select3" id="select3">

        <option>ALL DOCUMENT TYPES</option>

      </select></td>

    </tr>

  <tr>

    <td align="center" style="background-color:#C3DEF9"><input name="checkbox" type="checkbox" id="checkbox" /></td>

    <td class="dataHeader">Title</td>

    <td class="dataHeader">Document Type</td>

    <td class="dataHeader">Review Required</td>

    <td class="dataHeader">Document Date</td>

    <td width="75" class="dataHeader">Size</td>

    <td class="dataHeader">Upload Date</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>

    <td class="datacell">Family History Form - 00123</td>

    <td class="datacell">PATIENT FORM</td>

    <td class="datacell">JOHNSON, JACK</td>

    <td class="datacell">04/28/2009</td>

    <td class="datacell">233 KB</td>

    <td class="datacell">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>

    <td class="datacell2">LABCORP_06542335987</td>

    <td class="datacell2">LAB RESULT</td>

    <td class="datacell2">SMITH, MIKE</td>

    <td class="datacell2">04/28/2009</td>

    <td class="datacell2">1.4 MB</td>

    <td class="datacell2">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>

    <td class="datacell">Care Plan - Diabetes Type I</td>

    <td class="datacell">TEMPLATE</td>

    <td class="datacell">NOT REQUIRED</td>

    <td class="datacell">&nbsp;</td>

    <td class="datacell">186 KB</td>

    <td class="datacell">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox5" id="checkbox5" /></td>

    <td class="datacell2">Family History Form - 00124</td>

    <td class="datacell2">PATIENT FORM</td>

    <td class="datacell2">SMITH, MIKE</td>

    <td class="datacell2">04/27/2009</td>

    <td class="datacell2">233 KB</td>

    <td class="datacell2">04/27/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox6" id="checkbox6" /></td>

    <td class="datacell">HIPAA Consent - 006543</td>

    <td class="datacell">PATIENT FORM</td>

    <td class="datacell">NOT REQUIRED</td>

    <td class="datacell">04/27/2009</td>

    <td class="datacell">233 KB</td>

    <td class="datacell">04/27/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox7" id="checkbox7" /></td>

    <td class="datacell2">Family History Form - 00120</td>

    <td class="datacell2">PATIENT FORM</td>

    <td class="datacell2">JOHNSON, JACK</td>

    <td class="datacell2">04/26/2009</td>

    <td class="datacell2">233 KB</td>

    <td class="datacell2">04/26/2009</td>

  </tr>

</table>
 

<div style="background-color:#e5e5e5; margin-top:25px;">

    <div style="margin-left:auto; margin-right:auto; width:160px; padding-top:10px; padding-bottom:10px;">

    <input name="button3" type="button" class="frmButton" id="button3" value="Attach Selected" style="width:100px;" />

    <input name="button4" type="button" class="frmButton" id="button4" value="Cancel" onclick="javascript:window.close();" />

    </div>

  </div>
 

  </div>

</form>

</div>

</body>

</html>

Open in new window

0
Comment
Question by:Pdesignz
2 Comments
 
LVL 3

Accepted Solution

by:
GregTSmith earned 500 total points
ID: 24359527
I commented out radio3 and radio4, then moved radio and radio2 outside the "options" div tag, and it now works.

I figured it out by logging the event.srcElement.id to a new div tag I temporarily added to the bottom.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Attach a Document</title>

<script type="text/javascript">

	

 

function hide(id){

	document.getElementById(id).style.display='none';

}

function show(id){

	document.getElementById(id).style.display='';//'block'

}</script>

 

<style type="text/css">

<!--

#pageHeader { color: #FF9900; height: 18px; padding-top: 3px; padding-bottom: 3px; margin-top: 5px; margin-left: 5px; vertical-align: middle; text-align:left; font: bold 16px Arial, Helvetica, sans-serif; margin-bottom: 20px; }

#container ul { list-style: none; padding: 3px; margin: 0px; }

#upload table { margin-left: auto; margin-right: auto; width: 700px; }

#container { font-family: Arial, Helvetica, sans-serif; width: 900px; }

#options { width: 610px; margin-right: auto; margin-left: auto; font-weight: bold; }

#upload { width: 700px; margin-right: auto; margin-left: auto; font-weight: bold; }

#container li { display: inline; margin-right: 25px; }

/*#textfield { font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; height: 15px; border: 1px solid #6699CC; }*/

.dataHeader { font-weight: bold; color: #000000; line-height: 22px; text-indent: 2px; vertical-align: middle; text-align: left; background-color: #C3DEF9; padding: 1px; }

#upload table { font-weight: normal; }

 

-->

</style>

<link href="../HFPM_hybrid.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

 

<div id="container">

<div id="pageHeader">Attach a Document</div>

 

 

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

    <div style="margin-left:auto; margin-right:auto; width:610px; margin-bottom:20px;" class="instructions" >

  <ul>

  <li>  <input name="radio" type="radio" id="radio" checked="checked" onclick="hide('upload');show('options')" />

  Browse your  computer and upload a file</li>

  <li>   -OR- </li>

  <li>  <input type="radio" name="radio" id="radio2" onclick="hide('options');show('upload')" />

  Select a file from your document library </li>

  </ul>

  </div>
 

  <div id="options">

  <table cellpadding="1" cellspacing="1" style="width:450px; margin-left:10px;">

  <tr>

    <td>File Location</td>

    <td><input type="file" name="fileField" id="fileField" /></td>

  </tr>

  <tr>

    <td>Document Type</td>

    <td><select name="select" id="select" style="width:200px;">

      <option>Patient Form</option>

    </select>

    </td>

  </tr>

  <tr>

    <td>Title</td>

    <td><input name="textfield2" type="text" class="formfield" id="textfield2" style="width:250px;" value="Family History Form" /></td>

  </tr>

  <tr>

    <td>Document Date</td>

    <td><input name="textfield3" type="text" class="formfield" id="textfield3" value="04/28/2009" />

      <img src="../images/icon_calendar.png" width="18" height="16" /></td>

  </tr>

  <tr>

    <td>Review Required</td>

    <td><select name="select2" id="select2" style="width:200px;">

      <option>NO REVIEW REQUIRED</option>

      <option selected="selected">JOHNSON, JACK</option>

      <option>SMITH, MIKE</option>

    </select>

    </td>

  </tr>

</table>

<div style="background-color:#e5e5e5; margin-top:25px;">

    <div style="margin-left:auto; margin-right:auto; width:150px; padding-top:10px; padding-bottom:10px;">

    <input name="button3" type="button" class="frmButton" id="button3" value="Upload" />

    <input name="button4" type="button" class="frmButton" id="button4" value="Cancel" onclick="javascript:window.close();" />

    </div>

  </div>

</div>

 

<div id="upload" style="display:none;">

	<!--

  <div style="margin-left:auto; margin-right:auto; width:610px; margin-bottom:20px;" class="instructions" >

  <ul>

  <li>  

    <input type="radio" name="radio2" id="radio3" onclick="hide('upload');show('options')" />

    Browse your  computer and upload a file</li>

  <li>   -OR- </li>

  <li>

<input name="radio2" type="radio" id="radio4" checked="checked" onclick="hide('options');show('upload')" />    

Select a file from your document library </li>

  </ul>

  </div>

  -->

  <table cellspacing="1" cellpadding="1">

  <tr>

    <td colspan="7" style="text-align:right"><strong>Filter by:</strong>      <select name="select3" id="select3">

        <option>ALL DOCUMENT TYPES</option>

      </select></td>

    </tr>

  <tr>

    <td align="center" style="background-color:#C3DEF9"><input name="checkbox" type="checkbox" id="checkbox" /></td>

    <td class="dataHeader">Title</td>

    <td class="dataHeader">Document Type</td>

    <td class="dataHeader">Review Required</td>

    <td class="dataHeader">Document Date</td>

    <td width="75" class="dataHeader">Size</td>

    <td class="dataHeader">Upload Date</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>

    <td class="datacell">Family History Form - 00123</td>

    <td class="datacell">PATIENT FORM</td>

    <td class="datacell">JOHNSON, JACK</td>

    <td class="datacell">04/28/2009</td>

    <td class="datacell">233 KB</td>

    <td class="datacell">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>

    <td class="datacell2">LABCORP_06542335987</td>

    <td class="datacell2">LAB RESULT</td>

    <td class="datacell2">SMITH, MIKE</td>

    <td class="datacell2">04/28/2009</td>

    <td class="datacell2">1.4 MB</td>

    <td class="datacell2">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>

    <td class="datacell">Care Plan - Diabetes Type I</td>

    <td class="datacell">TEMPLATE</td>

    <td class="datacell">NOT REQUIRED</td>

    <td class="datacell">&nbsp;</td>

    <td class="datacell">186 KB</td>

    <td class="datacell">04/28/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox5" id="checkbox5" /></td>

    <td class="datacell2">Family History Form - 00124</td>

    <td class="datacell2">PATIENT FORM</td>

    <td class="datacell2">SMITH, MIKE</td>

    <td class="datacell2">04/27/2009</td>

    <td class="datacell2">233 KB</td>

    <td class="datacell2">04/27/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell"><input type="checkbox" name="checkbox6" id="checkbox6" /></td>

    <td class="datacell">HIPAA Consent - 006543</td>

    <td class="datacell">PATIENT FORM</td>

    <td class="datacell">NOT REQUIRED</td>

    <td class="datacell">04/27/2009</td>

    <td class="datacell">233 KB</td>

    <td class="datacell">04/27/2009</td>

  </tr>

  <tr>

    <td align="center" class="datacell2"><input type="checkbox" name="checkbox7" id="checkbox7" /></td>

    <td class="datacell2">Family History Form - 00120</td>

    <td class="datacell2">PATIENT FORM</td>

    <td class="datacell2">JOHNSON, JACK</td>

    <td class="datacell2">04/26/2009</td>

    <td class="datacell2">233 KB</td>

    <td class="datacell2">04/26/2009</td>

  </tr>

</table>

 

<div style="background-color:#e5e5e5; margin-top:25px;">

    <div style="margin-left:auto; margin-right:auto; width:160px; padding-top:10px; padding-bottom:10px;">

    <input name="button3" type="button" class="frmButton" id="button3" value="Attach Selected" style="width:100px;" />

    <input name="button4" type="button" class="frmButton" id="button4" value="Cancel" onclick="javascript:window.close();" />

    </div>

  </div>

 

  </div>

</form>

</div>

</body>

</html>

Open in new window

0
 

Author Closing Comment

by:Pdesignz
ID: 31597506
Great Work!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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)

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now