Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 JS - Showing / Hiding a DIV
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 02 May 2004 :  19:32:23  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
I am trying to show and hide a simple DIV using JS. Here is a very stripped down page that shows the code I am trying to use which does not work. Does anyone see any problems with this?


<SCRIPT LANGUAGE="Javascript">
	var AnswersAreShown;
	AnswersAreShown = true;

	function switchAnswersShown ()
	{
		If(AnswersAreShown)
		{
			document.getElementById('QuestionAnswers').style.visibility="hidden";
			AnswersAreShown = false;
		}else{
			document.getElementById('QuestionAnswers').style.visibility="visible";
			AnswersAreShown = true;
		}
	}
</SCRIPT>

Below is the form that will be hidden or displayed. <br> <INPUT TYPE="BUTTON" onClick="switchAnswersShown()" VALUE="View / Hide Form"> <br>

<div id="QuestionAnswers">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td width="100%" bgcolor="#FF0000">the form is shown</td>
  </tr>
</table>
</div>

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 02 May 2004 :  19:48:39  Show Profile
Javascript is case-sensitive, If should be if

The UK MkIVs Forum
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 02 May 2004 :  22:23:46  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
thanks, worked perfect. only problem i am having now is that when its hidden the rest of the info below whats hidden does not move up

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 03 May 2004 :  05:04:43  Show Profile  Visit D3mon's Homepage
used display:none instead. visibility:hidden is designed to mark out the space it would take up if it was visible.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 03 May 2004 :  11:51:49  Show Profile
i think display:none may be IE only, don't quote me on it though!

The UK MkIVs Forum
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 03 May 2004 :  11:53:48  Show Profile
I tend to use the Macromedia script to show/hide layers MM_showHideLayers as it works in all browsers

The UK MkIVs Forum
Go to Top of Page

Steve D.
Average Member

USA
640 Posts

Posted - 03 May 2004 :  14:07:44  Show Profile  Visit Steve D.'s Homepage  Send Steve D. a Yahoo! Message
display:none works on Opera too...

Swing Dancing Video Clips - It's All Swing! Forum
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 04 May 2004 :  12:08:12  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
David, What does macromedia's script look like?

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 04 May 2004 :  15:38:12  Show Profile
function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


then to show a div

showHideLayers('divName','','show')


you can put as many show/hide's as you want

showHideLayers('div1','','show','div2','','hide','div3','','show')

The UK MkIVs Forum
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 04 May 2004 :  15:55:06  Show Profile  Visit D3mon's Homepage
what happens if Javascript is disabled?


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 04 May 2004 :  16:16:13  Show Profile
quote:
Originally posted by D3mon

what happens if Javascript is disabled?



nothing

The UK MkIVs Forum
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.37 seconds. Powered By: Snitz Forums 2000 Version 3.4.07