Show/Hide Divs

Hi Paul, this has been incredibly helpful. I’ve been tasked with creating a page that does just this with only one being shown on the page load but I’m but having luck achieving this. When the page loads everything is shown, then hides as the links are clicked. Would you mind showing exactly where in the code the onclick event would go? I’m incredibly new to this so I apologize for the hand-holding.

Thanks!

I’ve moved this post out to a new thread since that other one was around a year old and only vaguely related to what’s happening.

Can you please show us what you currently have?

Paul, thank you for taking the time to assist, I apologize profusely for my minimal experience with all of this. I’ve been teaching myself things as I go so I’m sure I have some errors in my code.

As of now when the page loads all DIVs are shown, which is incorrect, then when I click a menu item everything disappears aside from that item and the DIV that isn’t assigned to a menu item, which is correct. My goal is to have just the DIV that isn’t assigned to a menu item when the page loads, then as you click the menu DIVs are shown/hidden accordingly.

I cannot begin to say how much I appreciate the help.

<?php
require_once('includes/config.php');
$_SESSION['qset']="false";
// FMStudio Pro - do not remove comment, needed for DreamWeaver support ?>
<?php
$found_user_find = $session->newFindCommand('php_users');
$found_user_findCriterions = array('ID_Contact'=>'=='.$_SESSION['user']);
foreach($found_user_findCriterions as $key=>$value) {
    $found_user_find->AddFindCriterion($key,$value);
}

fmsSetPage($found_user_find,'found_user',10);

$found_user_result = $found_user_find->execute();

if(FileMaker::isError($found_user_result)) fmsTrapError($found_user_result,"nopermission.php");

fmsSetLastPage($found_user_result,'found_user',10);

$found_user_row = current($found_user_result->getRecords());

?>

<!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>Welcome to the eMail Center</title>
<link rel="stylesheet" type="text/css" href="emailcenterstyle_test.css"/>
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script type="text/javascript">
<!--//---------------------------------+
//  Developed by Roshan Bhattarai
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
	//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
	$("#firstpane p.menu_head").click(function()
    {
		$(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
       	$(this).siblings().css({backgroundImage:"url(left.png)"});
	});
	//slides the element with class "menu_body" when mouse is over the paragraph
	$("#secondpane p.menu_head").mouseover(function()
    {
	     $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
         $(this).siblings().css({backgroundImage:"url(left.png)"});
	});
});
</script>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
  <!--        <script>
            function switchContent(obj) {
                obj = (!obj) ? 'sub1' : obj;

                var contentDivs = document.getElementsByTagName('div');
                for (i=0; i<contentDivs.length; i++) {
                    if (contentDivs[i].id && contentDivs[i].id.indexOf('sub') !== -1) {
                        contentDivs[i].className = 'hide';
                    }
                }
                document.getElementById(obj).className = '';
            }

            function checkTab() {
                $('a').each(function() {
                    $(this).click(function() {
                        tab = $(this).attr('href').split('#');
                        switchContent(tab[1]);
                        $('.current').attr('class','');
                        $(this).attr('class','current');
                    });
                });
            }

            window.onload = function() {
                checkTab();
            };

        </script> -->
<style type="text/css">

.menu_list {
	width: 250px;
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	font-size:12px;
	color:#FFFFFF;
	background-color:#060;
	height:850px;
	
	
}
.menu_head {
	padding: 5px 10px;
	cursor: pointer;
	position: relative;
	margin:1px;
    font-weight:bold;
    background: #060 url(left.png) center right no-repeat;
	border:thin;
	border-bottom-color:#FFF;
	border-top-color:#FFFFFF;
	
}
.menu_body {
	display:none;
}
.menu_body a {
  padding: 5px 10px;
  display:block;
  color:#FFFFFF;
  background-color:#666666;
  padding-left:10px;
  text-decoration:none;
  line-height: 24px;
  border:thin;
	border-bottom-color:#FFF;
	border-top-color:#FFFFFF;
}
.menu_body a:link {
	  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;
}
.menu_body a:visited {
	  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;
}
.menu_body a:hover {
  color: #FFFFFF;
  text-decoration:underline;
  font-weight:bold;
}
.menu_body a:active {
  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;

}
.menu_head a {
  display:block;
  color:#FFFFFF;
  background-color:#060;
  text-decoration:none;

  border:thin;
	border-bottom-color:#FFF;
	border-top-color:#FFFFFF;
}
.menu_head a:link {
	  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;
}
.menu_head a:visited {
	  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;
}
.menu_head a:hover {
  color: #FFFFFF;
  text-decoration:underline;
  font-weight:bold;
}
.menu_head a:active {
  color: #FFFFFF;
  text-decoration:none;
  font-weight:bold;

}
.welcome {
	float:left;
	margin-left:auto;
	margin-right:auto;
	padding:25px;
	width:475px;
	text-align:left;
	vertical-align:middle;
}
.welcome p{
	line-height:6px;
}
 /* .hide {
                display: none;
            }     */
            .current{
                color: black;
            }
.hidden {
    display: none;
}
</style>


</head>
	<body>
    <div id="container">
		<?php include('includes/menu_header_DD.php'); ?>
<div style="float:left;" > <!--This is the first division of left-->
  <div id="tabs">
  <div id="firstpane" class="menu_list"> <!--Code for menu starts here-->
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p class="menu_head"><a href="#def_CLP">CLP</a></p>
		<div class="menu_body">
		<a href="#def_welcome">Welcome Training Email</a>
         <a href="#def_renewal">Renewal Kickoff Email</a>
         <a href="#def_loyal">Loyalty Training Email</a>	
         <a href="#def_usage">Usage Statements</a>	
		</div>
		<p class="menu_head"><a href="#def_elinks">Elinks</a></p>
	<div class="menu_body">
       </div>
		<p class="menu_head"><a href="#def_stimlulation">Usage Stimulation Email</a></p>
		<div class="menu_body">
       </div>
       <p class="menu_head"><a href="#def_cert">Certified Trainer Email</a></p>
		<div class="menu_body">
       </div>
        <p class="menu_head"><a href="#def_access">Access and Integration Email</a></p>
		<div class="menu_body">
       </div>
       		<p>&nbsp;</p>
		<p>&nbsp;</p>
        <p>&nbsp;</p>
		<p>&nbsp;</p>

  </div>  </div></div>
        <div class="welcome">


            <div id=""><h1>Welcome to the Email Center</h1><hr /></div>

            <div id="def_CLP"><h3>CLP</h3>
<h2>definition</h2></div>

          <div id="def_welcome"><h3>Welcome Training Email</h3>
<h2>Email to new customers introducing training program and materials</h2>
<p><img src="images/SubscriptionWelcomePage.jpg" /></p><?php echo "<a href='emailCenter_new.php?type=welcome'><img src='images/But_sendemail.jpg' /></a>";?>
          </div>

          <div id="def_renewal"><h3>Renewal Kickoff Email</h3>
<h2>Email to current customers to start renewal process</h2>
<p><img src="images/SubscriptionRenewPage.jpg" /></p><?php echo "<a href='emailCenter_new.php?type=elink'><img src='images/But_sendemail.jpg' /></a>"; ?></div>

            <div id="def_loyal"><h3>Loyalty Training Email</h3>
<h2>Email to current customers after renewal is complete to introduce training program</h2>
<p><img src="images/SubscriptionLoyaltyPage.jpg" /></p><?php echo "<a href='emailCenter_new.php?type=cert'><img src='images/But_sendemail.jpg' /></a>";?></div>

          <div id="def_usage"><h3>Usage Statements</h3>
           <p><img src= /></p><a href='#'><img src='images/But_usagestate.jpg' /></a></div>

          <div id="def_elinks"><h3>Elinks</h3>
           <p><img src= /></p><?php echo "<a href='emailCenter_new.php?type=elink'><img src='images/But_elinks.jpg'></a>";?></div>

          <div id="def_stimlulation"><h3>Usage Stimulation Email</h31>
          <p><img src= /></p><a href='#'><img src='images/But_sendemail.jpg' /></a></div>

          <div id="def_cert"><h3>Certified Trainer Email</h3>
<h2>Congratulatory email to new Certified Trainers</h2>
<p><img src= /></p><a href='#'><img src='images/But_sendemail.jpg' /></a></div>

          <div id="def_access"><h3>Access and Integration Email</h3>
<h2>Integration pre-call email</h2>
<p><img src="images/SubscriptionAccess.jpg" /></p><a href='#'><img src='images/But_sendemail.jpg' /></a></div>
        </div>


		<p>&nbsp;</p>
		<?php include('includes/footer.php'); ?>
    </div> <!-- Container -->

  <script>

var tabs = document.getElementById('tabs');
tabs.onclick = function (evt) {
    evt = evt || window.event;
    var link = evt.target || evt.srcElement,
        links,
        i,
        target;
    if (link.nodeType === 1 && link.nodeName === 'A') {
        links = this.getElementsByTagName('a');
        for (i = 0; i < links.length; i += 1) {
            target = document.getElementById(links[i].href.split('#')[1]);
            if (link !== links[i]) {
                target.className = 'hidden';
            } else {
                target.className = '';
            }
        }
        return false;
    }

};
  tabs.getElementsByTagName('a')[0].click();
</script>
<script src="script.js"></script>
  </body>
</html>

You have jquery loading twice, which is not a good start.

Try fixing that up first, then see how things go.

I commented out the on at the bottom but did I actually have it loading 3 times? I found these…


<script type="text/javascript" language="javascript" src="jquery.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>

<script src="script.js"></script>

doing some reading online it looks like the jquery.min.js is the better to use, is this the case or are they used for different things?

Yes, not just because it’s min, but because it’s from an online location that many other visitors are already likely to have too, meaning that their web browser then doesn’t need to download the file because it already has it in its cache.

That’s also why it’s a good reason to use a more recent version of jQuery.

Is this the most recent?

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

either way I’m still not having luck hiding everything when the page loads, should I have all my scripts together in the bottom on the page? Right now I think I have the scripts for the menu at the top of the code and the scripts for the DIVs at the bottom of the code.

Thank you again for your patience and help :slight_smile: