Solved

Hiding and showing divs using javascript

Posted on 2008-10-09
2
272 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
Comment Utility
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
Comment Utility
This worked perfectly thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now