Solved

Hiding and showing divs using javascript

Posted on 2008-10-09
2
275 Views
Last Modified: 2012-05-05
The attached code snippet gives my attempt to hide and show divs using javascript.  Right now I am not getting any response from any of the radio button clicks and just need some help understanding why.



THE JAVASCRIPT FUNCTION:
 

function show_div(div_id) {

    // hide all the divs

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

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

    // show the requested div

    document.getElementById(div_id).style.display = 'block';

}
 
 
 

THE CALL TO THE JAVASCRIPT FUNCTION
 

		<tr>

			<td align="right">Content Type:

			</td>

			<td>

				Remote: <input type="radio" name="CreativeContentType" value="Remote" <cfif #CreativeContent.CreativeContentType# eq 'Remote'>checked</cfif> onclick="show_div('url'); return false;">

				Hosted: <input type="radio" name="CreativeContentType" value="Hosted" <cfif #CreativeContent.CreativeContentType# eq 'Hosted'>checked</cfif> onclick="show_div('content'); return false;">

			</td>

		</tr>
 
 
 
 
 

THE DEFINED DIVS
 

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

			<tr>

				<td nowrap align="right" valign="top">URL: 

				

				</td>

				<td nowrap>

					<INPUT TYPE="text" SIZE=80 NAME="RemoteContentUrl" ID="RemoteContentUrl" class="Forminput" value="#CreativeContent.RemoteContentUrl#">&nbsp;

					<input name="Content" type="hidden" value="">

				</td>

			</tr>

		</div>

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

			<tr>

				<td align="right">Content:

				</td>

	

				<td><input name="RemoteContentUrl" type="hidden" value="">

					<textarea name="Content" id="Content" cols="100" rows="12" wrap="soft" 

						class="OptsFormData">#CreativeContent.Content#</textarea>

				</td>

			</tr> 

		</div>

Open in new window

0
Comment
Question by:onaled777
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 22678616
get rid of the div tags and instead move the:
style="display: none;" id="url" to the tr element. A table may NOT have div around tr, so the browser is ignoring that markup. Ultimately your markup should look similar to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
//THE JAVASCRIPT FUNCTION: 
function show_div(div_id) {
    // hide all the divs
    document.getElementById('url').style.display = 'none';
    document.getElementById('content').style.display = 'none';
 
    // show the requested div
    document.getElementById(div_id).style.display = 'block';
}
 
 </script>
 
<!-- THE CALL TO THE JAVASCRIPT FUNCTION -->
 <table>
                <tr>
                        <td align="right">Content Type:
                        </td>
                        <td>
                                Remote: <input type="radio" name="CreativeContentType" value="Remote" onclick="show_div('url'); ">
                                Hosted: <input type="radio" name="CreativeContentType" value="Hosted" onclick="show_div('content'); ">
                        </td>
                </tr>
  
 
 
 
<!-- THE DEFINED DIVS -->
  
                        <tr style="display: none;" id="url">
                                <td nowrap align="right" valign="top">URL: 
                                
                                </td>
                                <td nowrap>
                                        <INPUT TYPE="text" SIZE=80 NAME="RemoteContentUrl" ID="RemoteContentUrl" class="Forminput" value="#CreativeContent.RemoteContentUrl#"> 
                                        <input name="Content" type="hidden" value="">
                                </td>
                        </tr> 

                        <tr style="display: none;" id="content">
                                <td align="right">Content:
                                </td>
        
                                <td><input name="RemoteContentUrl" type="hidden" value="">
                                        <textarea name="Content" id="Content" cols="100" rows="12" wrap="soft" 
                                                class="OptsFormData">#CreativeContent.Content#</textarea>
                                </td>
                        </tr>
 </table>
</body>
</html>

Open in new window

0
 

Author Comment

by:onaled777
ID: 22679164
This worked perfectly thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now