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)
 javascript files
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

snaayk
Senior Member

USA
1061 Posts

Posted - 09 November 2003 :  10:06:17  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
Why is it that when I use the following code, the page works as intended:

<script type="text/javascript">
<!--
	function showHideTable(id,theImg)
	{
		if (document.getElementById(id).style.display == 'none')
		{
			document.getElementById(id).style.display = 'block';
			document.getElementById(theImg).src='/imgages/collapse.gif';
		}
		else
		{
			document.getElementById(id).style.display = 'none';
			document.getElementById(theImg).src='http:/imgages/expand.gif';
		}
	}
//-->
</script>


However, if I try to place the code in a js file (with all the separate javascript I use around the site, like pop-up windows) I get an error?
Like this:

<script src="common/javascripts/jacasvripts.js"></script>

in file:

function showHideTable(id,theImg)
{
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
		document.getElementById(theImg).src='/imgages/collapse.gif';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(theImg).src='http:/imgages/expand.gif';
	}
}

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 09 November 2003 :  11:15:57  Show Profile
check the spelling of your js file

<script src="common/javascripts/jacasvripts.js"></script>

should it not be

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

The UK MkIVs Forum

Edited by - DavidRhodes on 09 November 2003 14:28:56
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 09 November 2003 :  14:06:41  Show Profile  Visit dayve's Homepage
This doesn't look right for several reasons:

document.getElementById(theImg).src='http:/imgages/expand.gif'

images is spelled incorrectly
prefix of http:/ is unecessary AND used incorrectly


Edited by - dayve on 09 November 2003 14:06:59
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 09 November 2003 :  22:29:40  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
I apologize, I should have copied and pasted. Those errors do not exist in the actual files
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 11 November 2003 :  13:41:02  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
I feel silly: it's actually another script in the file. Starnge..

Dayve, I know you have a similar function on your site. Are you using cookies to remeber the status of the div? I wanted to add a function to remeber the status of each div.
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 11 November 2003 :  13:50:00  Show Profile  Visit dayve's Homepage
On my forum I elected to not use cookies, but I am using the same script on other sites with cookies with great success. I found a canned javascript cookie script that I use in conjunction with my show/hide script. I can post a working example of it tomorrow if you would like.

Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 11 November 2003 :  14:12:49  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
I would much appreciate it, thanks.
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 12 November 2003 :  17:09:34  Show Profile  Visit dayve's Homepage
Put this in the <head></head> tags:


<script>
function ShowHide(elementName) {
	var HeaderElement = null;
	var BodyElement = null; 
	delCookie(elementName);

	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		
		if(BodyElement) {	
			if(BodyElement[0].style.display == "none") {
				setCookie(elementName,'show');
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "ListNuggetHeader";
			} else {
				delCookie(elementName);
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "ListNuggetHeaderClosed";
			}
		}	
	}
		window.event.cancelBubble = true;
		return false;
}

function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
</script>

<style>
.ListNuggetHeader {
	WIDTH: 100%; CURSOR: hand;
}
.ListNuggetHeaderClosed {
	WIDTH: 100%; COLOR: black;
}
.ListNuggetBody {
	PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; 
}
.ListNuggetUpButton {
	DISPLAY: none
}
.ListNuggetDownButton {
	
}
</style>


and then wherever you want to place a show/hide menu add this:


 	   <!-- Drop Down Menu Container -->
		<DIV>
		 <DIV style="WIDTH: 100%">
		  <TABLE class="ListNuggetHeader" cellSpacing="0" cellPadding="0" border="0" width="100%" id="calHeader" name="calHeader">
		   <TR>
			<TD onclick="ShowHide('cal');">
			DROP DOWN TITLE HERE
                        </TD>
		   </TR>
		   <TR>
			<TD width="100%">			
			<script>
			  menuView=(getCookie('cal')=="show")?"block":"none";
			  document.writeln ("<DIV style='display:" + menuView + ";' id='calBody' name='calBody'>")
			</script>		  
			  <DIV>
			   <TABLE class="ListNuggetBody" cellSpacing="0" cellPadding="0" border="0">
				<TR>
				 <TD>
                                 Drop Down Stuff Here
				 </DIV>
				</DIV>
			   </TD>
			  </TR>
			 </TABLE>	
			</TD>
		   </TR>
		  </TABLE>		
		 </DIV>
	    <!-- Drop Down Menu Container -->


you have to uniquely identify the red areas. the css can be modified for your needs, but that is the basics that are required.


Edited by - dayve on 12 November 2003 17:11:50
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 05 December 2003 :  16:02:50  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
BTW, thanks!
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.28 seconds. Powered By: Snitz Forums 2000 Version 3.4.07