Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] Change DIV Content


Change DIV Content

Closed Thread
  #1 (permalink)  
Old 11-22-09, 07:54 PM
kcorbishley kcorbishley is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 49
Thanks: 2
Thanked 0 Times in 0 Posts
Change DIV Content

Hi,
I hope someone will be able to help me, this is my first time using this website.
If you have a look at the site (link below), you can see 8 links on the left handside (all roll over image effect) and a large white are with content "Welcome to...".
What I am looking to do is have the current content you see in the white box show as default but when one of the links on the left hand side are clicked for the content to change to relevent content for that subject. As from what i can gather this can be done using DIVs but im not sure how as i have never done this before. Im assuming ill have to enter the content for each link in a DIV and give each DIV an ID and when a link is clicked it shows only the DIV its linked to.
Can anyone help with a script. I don't mind if the script needs to be included on the same page or a seperate .js page that I can link to the site.

The website Compu Tech Midlands

Regards,

kcorbishley
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #2 (permalink)  
Old 11-22-09, 08:31 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Not tested.

HTML Code:
<div id="menu_area">
<a onclick="display_area('content_1')">Content 1</a>
<a onclick="display_area('content_2')">Content 2</a>
</div>
<div id="content_area">
<div id="default_content">
Displayed on initial page load.
</div>
<div id="content_1" style="display:none">
Content 1
</div>
<div id="content_2" style="display:none">
Content 2
</div>
</div>
</body>
<script type="text/javascript">
var dLast=document.getElementById('default_content');
var dCurrent;
function display_area(s)
{
new_area=document.getElementById('s');
dLast.style.display="none";
new_area.style.display="block";
dLast=new_area;
}
</script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #3 (permalink)  
Old 11-23-09, 11:23 AM
kcorbishley kcorbishley is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 49
Thanks: 2
Thanked 0 Times in 0 Posts
Doesn't Work

Thank you for your help. Unfortunately the code you suggested doesnt work, it shows no content in that cell. I have copied the script to my whole page below to see if you can spot any more errors.

HTML Code:
<!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>Compu Tech Midlands</title>
<link href="global.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('images/links/home_hov.png','images/links/sr_hov.png','images/links/up_hov.png','images/links/cust_hov.png','images/links/net_hov.png','images/links/web_hov.png','images/links/host_hov.png','images/links/contact_hov.png')">
<table align="center" width="948" border="0" cellspacing="5" cellpadding="0">
  <tr>
    <td class="header" colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td class="flash" align="center" valign="middle" colspan="2"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','938','height','150','src','main','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','main' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="938" height="150">
      <param name="movie" value="main.swf" />
      <param name="quality" value="high" />
      <embed src="main.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="938" height="150"></embed>
    </object></noscript></td>
  </tr>
  <tr>
    <td width="173" valign="top" align="center">
    	<table width="173" border="0" cellspacing="0" cellpadding="0">
  			<tr>
   			  <td class="links" align="center" valign="middle">
              	<div id="menu_area">
                	<table width="163" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><a onclick="display_area('default_content')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/links/home_hov.png',1)"><img src="images/links/home.png" name="home" width="163" height="23" border="0" id="home" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_2')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('sr','','images/links/sr_hov.png',1)"><img src="images/links/sr.png" name="sr" width="163" height="23" border="0" id="sr" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_3')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('up','','images/links/up_hov.png',1)"><img src="images/links/up.png" name="up" width="163" height="23" border="0" id="up" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_4')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('cust','','images/links/cust_hov.png',1)"><img src="images/links/cust.png" name="cust" width="163" height="23" border="0" id="cust" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_5')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('net','','images/links/net_hov.png',1)"><img src="images/links/net.png" name="net" width="163" height="23" border="0" id="net" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_6')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('web','','images/links/web_hov.png',1)"><img src="images/links/web.png" name="web" width="163" height="23" border="0" id="web" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_7')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('host','','images/links/host_hov.png',1)"><img src="images/links/host.png" name="host" border="0" id="host" /></a></td>
  </tr>
  <tr>
    <td><a onclick="display_area('content_8')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','images/links/contact_hov.png',1)"><img src="images/links/contact.png" name="contact" width="163" height="23" border="0" id="contact" /></a></td>
  </tr>
</table>
		</div>
              </td>
  			</tr>
		</table>
    </td>
<td width="770" valign="top">
    	<table width="770" border="0" cellspacing="0" cellpadding="0">
  			<tr>
   			  <td class="main" valign="top">
              <div class="main">
              <h1><strong>Welcome to CompuTech Midlands</strong></h1>
      <p>&nbsp;</p>
      <p>We provide   individuals and companies with a one stop shop approach to I.T. maintenance and website design. We look into every situation in a unique way and offer the best resolution whilst keeping in mind the need of low cost solutions for all issues from PC faults to networking.</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p><strong>Experiencing a computer problem? <a href="#">Contact us here</a></strong>.</p>
      <p>&nbsp;</p>
      <p>Whether you are an individual or a business we will arrive at your home/office and aim to resolve all problems at your home/office,</p>
      <p>We can provide you with a tailored website   services to get the most from your online presence. We offer a arrange of website solutions ranging from brochure sites showcasing your companies products   and services to shopping sites and existing website updates, we can help. We also offer great value hosting to compliment your website.</p>
      <p>&nbsp;</p>
      <p><strong>Looking for a website? <a href="#">Take a look at our web development packages</a></strong>.</p>
    <p>&nbsp;</p>
                </div>
		      </td>
  			</tr>
  			<tr>
    			<td class="bmain">&nbsp;</td>
  			</tr>
		</table>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
Thank you again for your input and trying to help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #4 (permalink)  
Old 11-23-09, 12:42 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Try taking 'display:none' off this div.

HTML Code:
<div id="default_content" style="display:none">
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #5 (permalink)  
Old 11-23-09, 01:02 PM
kcorbishley kcorbishley is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 49
Thanks: 2
Thanked 0 Times in 0 Posts
Still Not Working

Thanks for trying again for me, this time it shows the content in the default_content div, but when i click on any of the links in clears the cell again and when i click on the link to show default_content div it shows clear cell. and error message comes up adving couldnt call object on the line that contains new_area.style.display="block" in the javascript.
thanks again tho.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #6 (permalink)  
Old 11-23-09, 01:27 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Sorry - take the quotes off arround the s.

Code:
new_area=document.getElementById(s);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #7 (permalink)  
Old 11-23-09, 01:57 PM
kcorbishley kcorbishley is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 49
Thanks: 2
Thanked 0 Times in 0 Posts
We got there!!!

Your a life saver! I can't thank you enough for your help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #8 (permalink)  
Old 11-23-09, 04:46 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Glad it worked out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #9 (permalink)  
Old 11-23-09, 05:33 PM
kcorbishley kcorbishley is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 49
Thanks: 2
Thanked 0 Times in 0 Posts
Im goin to be a pain again but you are extremly helpful and obviously know what your doin. I am looking to add a flash banner on the site advising that the business sells and installs windows 7, How can i link it in so that the flash banner can change the content in the main cell to its related info.
I know im asking alot here and may be out of your depth, but i thought it would be worth asking. I didnt know if i'd have to creat the link within flash using action script (if so, what code would i use to link it to the main content and not affect the side links) or could i just turn the flash banner into a link using code on the actual site page.
Sorry again for being a pain, just trying ge tthis site lookin the best i can and thought I'd ask with it stil bein linked with the DIV content change.

Regards,

kcorbishley
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #10 (permalink)  
Old 11-26-09, 05:33 PM
lauren06 lauren06 is offline
New Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi...
No need to feel sorry...
We are here to help one another.
you can very well create the link within flash using action script

Last edited by End User; 11-26-09 at 09:54 PM. Reason: Removed advertising link
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
make element follow page scroll ?! how-to k-knudsen JavaScript 12 08-04-09 03:03 PM
Make a div follow page scroll - the continued k-knudsen JavaScript 7 07-25-09 04:38 AM
[SOLVED] Change content in a DIV with links in another DIV s1yfa JavaScript 3 05-04-08 05:10 AM
Error On Registeration timmy408 ASP 2 09-05-04 03:53 PM


All times are GMT -5. The time now is 06:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.