Solved

Hiding and showing divs using javascript

Posted on 2008-10-09
2
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

749 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