Solved

Hiding and showing divs using javascript

Posted on 2008-10-09
2
288 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

623 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