Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script not defined error

    Hi all,

    Trying to use a small bit of script to slide open and closed a div.
    Copied it from another page where I have it working just fine. Coding in coldfusion.

    When clicked, nothing happens, and firebug pulls an error of DC_ShowDeptStaff is undefined.

    Script is:
    Code:
    <script type="text/javascript">
    	function DC_ShowDeptStaff(){
    		if( document.getElementById("testdiv").style.display=="none" ) {
    			Effect.BlindDown("testdiv"); 
    			 return false;
    		} else {
    			Effect.SlideUp("testdiv");  return false;
    		}
    	}
    	</script>
    Call is:
    Code:
    <a href="javascript:;" onclick="DC_ShowDeptStaff()" return false;>See All Staff in this Department</a>
    Full code is:
    Code:
    <script type="text/javascript">
    	function DC_ShowDeptStaff(){
    		if( document.getElementById("testdiv").style.display=="none" ) {
    			Effect.BlindDown("testdiv"); 
    			 return false;
    		} else {
    			Effect.SlideUp("testdiv");  return false;
    		}
    	}
    	</script>
    	
    
    
    
    <cfquery name="getStaffProfileDepartments" datasource="#ATTRIBUTES.datasource#" username="#ATTRIBUTES.username#" password="#ATTRIBUTES.password#">
    SELECT		spd.staffProfileDepartmentName,
    			spd.staffProfileDepartmentId
    FROM		dccom_twstaffprofilesdepartments spd
    WHERE		spd.instanceId		=	<cfqueryparam value = "#REQUEST.instanceId#">
    		AND	spd.staffProfileDepartmentIsPublished	=	'YES'
    ORDER BY	spd.staffProfileDepartmentDisplayOrder,
    			spd.staffProfileDepartmentName
    </cfquery>
    <cfif getStaffProfileDepartments.RecordCount NEQ 0>
    	<cfloop query="getStaffProfileDepartments">
    		<!---INSIDE LOOP ONE--->
    		<cfoutput>
    			<h3>#staffProfileDepartmentName#</h3>
    			<h4><a href="javascript:;" onclick="DC_ShowDeptStaff()" return false;>See All Staff in this Department</a></h4><br>
    				<div class="testdiv" style="display: none"><h3>Test Success!</h3></div>
    		
    		
    						<cfquery name="getStaffProfiles" datasource="#ATTRIBUTES.datasource#" username="#ATTRIBUTES.username#" password="#ATTRIBUTES.password#">
    						SELECT		sp.staffProfileId,
    									sp.staffProfileName,
    									sp.staffProfilePosition,
    									sp.staffProfilePhone,
    									sp.staffProfileMobile,
    									sp.staffProfileEmail,
    									sp.staffProfileDescription,
    									sp.staffProfileImage,
    									sp.staffProfileDisplayOrder,
    									spd.staffProfileDepartmentName,
    									sp.staffProfileIsDepartmentHead,
    									sp.staffProfileIsPublished
    						FROM		dccom_twstaffprofiles sp	LEFT OUTER JOIN	dccom_twstaffprofilesdepartments spd 	ON	sp.staffProfileDepartmentId = spd.staffProfileDepartmentId
    									AND	sp.instanceId	= 	spd.instanceId
    						WHERE		sp.instanceId		=	<cfqueryparam value = "#REQUEST.instanceId#">
    								AND	sp.staffProfileIsPublished	=	'YES'
    								AND spd.staffProfileDepartmentId = <cfqueryparam value="#staffProfileDepartmentId#">
    
    						ORDER BY	sp.staffProfileIsDepartmentHead DESC,
    									sp.staffProfileDisplayOrder,
    									sp.staffProfilePosition
    									
    						</cfquery>
    						<cfif getStaffProfiles.RecordCount NEQ 0>
    							<cfloop query="getStaffProfiles">
    								<cfoutput>			
    									<ul>
    										<cfset cStaffProfileDescription = staffProfileDescription>		
    										<cfset cStaffProfileDescription = replace(replace(cStaffProfileDescription,chr(13) & chr(10),"<br>","ALL"),chr(10),"<br>","ALL")>		
    										<li>
    											
    											<cfif staffProfileIsDepartmentHead EQ 'YES'>
    												<div class="staffInfo">
    													<h3>#staffProfileName#</h3>
    													<h3>DEPT HEAD</h3>
    													<cfif LEN(#staffProfilePosition#)><h4>#staffProfilePosition#</h4></cfif>
    													<cfif LEN(#staffProfilePosition#)><p>#cStaffProfileDescription#</p></cfif>
    													<cfif LEN(#staffProfilePhone#)><p>Phone: #staffProfilePhone#</p></cfif>
    													<cfif LEN(#staffProfileMobile#)><p>Mobile: #staffProfileMobile#</p></cfif>
    													<cfif LEN(#staffProfileEmail#)><p><a href="mailto:#staffProfileEmail#">#staffProfileEmail#</a></p></cfif>						
    												</div>
    												<cfif LEN(#staffProfileImage#)>
    													<div class="staffImage">
    														<cfif LEN(staffProfileImage) AND fileExists(APPLICATION.siteFilePath & "contentFiles\components\twStaffProfiles\" & REQUEST.instanceId & "\" & staffProfileImage)><img src="contentFiles/components/twStaffProfiles/#REQUEST.instanceId#/#staffProfileImage#" width="100" height="120" alt="#staffProfilePosition#">
    														</cfif>
    													</div>
    												</cfif>
    											
    											<cfelse>
    												<h3>HIDDEN STAFF PROFILE</h3>
    												<div class="staffInfo2" style="display:none" >
    												<h3>#staffProfileName#</h3>
    												<cfif LEN(#staffProfilePosition#)><h4>#staffProfilePosition#</h4></cfif>
    												<cfif LEN(#staffProfilePosition#)><p>#cStaffProfileDescription#</p></cfif>
    												<cfif LEN(#staffProfilePhone#)><p>Phone: #staffProfilePhone#</p></cfif>
    												<cfif LEN(#staffProfileMobile#)><p>Mobile: #staffProfileMobile#</p></cfif>
    												<cfif LEN(#staffProfileEmail#)><p><a href="mailto:#staffProfileEmail#">#staffProfileEmail#</a></p></cfif>
    									
    												</div>
    												<cfif LEN(#staffProfileImage#)>
    													<div class="staffImage">
    														<cfif LEN(staffProfileImage) AND fileExists(APPLICATION.siteFilePath & "contentFiles\components\twStaffProfiles\" & REQUEST.instanceId & "\" & staffProfileImage)><img src="contentFiles/components/twStaffProfiles/#REQUEST.instanceId#/#staffProfileImage#" width="100" height="120" alt="#staffProfilePosition#">
    														</cfif>
    													</div>
    												</cfif>
    											</cfif>
    										
    										</li>
    									</ul>
    								</cfoutput>
    							</cfloop>
    						<cfelse>
    							<cfoutput>
    								<p>There are Currently No Staff Listed in this Department</p>
    								<br>
    							</cfoutput>
    						</cfif>
    						</cfoutput>
    				<!---end loop one--->	
    	</cfloop>
    </cfif>
    any input would be appreciated

  • #2
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay,
    I'm an idiot, didn't have the script wrapped in cfoutput tags.

    Now the error is as follows
    document.getElementById("staffInfo2") is null
    if( document.getElementById( "staffInfo2").style.display=="none" ) {
    Current code looks like
    Code:
    <cfoutput>
    	<script type="text/javascript">
    	function DC_ShowDeptStaff(){
    		if( document.getElementById( "staffInfo2").style.display=="none" ) {
    			Effect.BlindDown( "staffInfo2"); 
    			 return false;
    		} else {
    			Effect.SlideUp( "staffInfo2");  return false;
    		}
    	}
    	</script>
    </cfoutput>
    	
    
    
    
    <cfquery name="getStaffProfileDepartments" datasource="#ATTRIBUTES.datasource#" username="#ATTRIBUTES.username#" password="#ATTRIBUTES.password#">
    SELECT		spd.staffProfileDepartmentName,
    			spd.staffProfileDepartmentId
    FROM		dccom_twstaffprofilesdepartments spd
    WHERE		spd.instanceId		=	<cfqueryparam value = "#REQUEST.instanceId#">
    		AND	spd.staffProfileDepartmentIsPublished	=	'YES'
    ORDER BY	spd.staffProfileDepartmentDisplayOrder,
    			spd.staffProfileDepartmentName
    </cfquery>
    <cfif getStaffProfileDepartments.RecordCount NEQ 0>
    	<cfloop query="getStaffProfileDepartments">
    		<!---INSIDE LOOP ONE--->
    		<cfoutput>
    			<h3>#staffProfileDepartmentName#</h3>
    			<h4><a href="javascript:;" onclick="DC_ShowDeptStaff(); return false">See All Staff in this Department</a></h4><br>
    
    		
    		
    						<cfquery name="getStaffProfiles" datasource="#ATTRIBUTES.datasource#" username="#ATTRIBUTES.username#" password="#ATTRIBUTES.password#">
    						SELECT		sp.staffProfileId,
    									sp.staffProfileName,
    									sp.staffProfilePosition,
    									sp.staffProfilePhone,
    									sp.staffProfileMobile,
    									sp.staffProfileEmail,
    									sp.staffProfileDescription,
    									sp.staffProfileImage,
    									sp.staffProfileDisplayOrder,
    									spd.staffProfileDepartmentName,
    									sp.staffProfileIsDepartmentHead,
    									sp.staffProfileIsPublished
    						FROM		dccom_twstaffprofiles sp	LEFT OUTER JOIN	dccom_twstaffprofilesdepartments spd 	ON	sp.staffProfileDepartmentId = spd.staffProfileDepartmentId
    									AND	sp.instanceId	= 	spd.instanceId
    						WHERE		sp.instanceId		=	<cfqueryparam value = "#REQUEST.instanceId#">
    								AND	sp.staffProfileIsPublished	=	'YES'
    								AND spd.staffProfileDepartmentId = <cfqueryparam value="#staffProfileDepartmentId#">
    
    						ORDER BY	sp.staffProfileIsDepartmentHead DESC,
    									sp.staffProfileDisplayOrder,
    									sp.staffProfilePosition
    									
    						</cfquery>
    						<cfif getStaffProfiles.RecordCount NEQ 0>
    							<cfloop query="getStaffProfiles">
    								<cfoutput>			
    									<ul>
    										<cfset cStaffProfileDescription = staffProfileDescription>		
    										<cfset cStaffProfileDescription = replace(replace(cStaffProfileDescription,chr(13) & chr(10),"<br>","ALL"),chr(10),"<br>","ALL")>		
    										<li>
    											
    											<cfif staffProfileIsDepartmentHead EQ 'YES'>
    												<div class="staffInfo">
    													<h3>#staffProfileName#</h3>
    													<h3>DEPT HEAD</h3>
    													<cfif LEN(#staffProfilePosition#)><h4>#staffProfilePosition#</h4></cfif>
    													<cfif LEN(#staffProfilePosition#)><p>#cStaffProfileDescription#</p></cfif>
    													<cfif LEN(#staffProfilePhone#)><p>Phone: #staffProfilePhone#</p></cfif>
    													<cfif LEN(#staffProfileMobile#)><p>Mobile: #staffProfileMobile#</p></cfif>
    													<cfif LEN(#staffProfileEmail#)><p><a href="mailto:#staffProfileEmail#">#staffProfileEmail#</a></p></cfif>						
    												</div>
    												<cfif LEN(#staffProfileImage#)>
    													<div class="staffImage">
    														<cfif LEN(staffProfileImage) AND fileExists(APPLICATION.siteFilePath & "contentFiles\components\twStaffProfiles\" & REQUEST.instanceId & "\" & staffProfileImage)><img src="contentFiles/components/twStaffProfiles/#REQUEST.instanceId#/#staffProfileImage#" width="100" height="120" alt="#staffProfilePosition#">
    														</cfif>
    													</div>
    												</cfif>
    											
    											<cfelse>
    												<h3>HIDDEN STAFF PROFILE</h3>
    												<div class="staffInfo2" style="display:none" >
    												<h3>#staffProfileName#</h3>
    												<cfif LEN(#staffProfilePosition#)><h4>#staffProfilePosition#</h4></cfif>
    												<cfif LEN(#staffProfilePosition#)><p>#cStaffProfileDescription#</p></cfif>
    												<cfif LEN(#staffProfilePhone#)><p>Phone: #staffProfilePhone#</p></cfif>
    												<cfif LEN(#staffProfileMobile#)><p>Mobile: #staffProfileMobile#</p></cfif>
    												<cfif LEN(#staffProfileEmail#)><p><a href="mailto:#staffProfileEmail#">#staffProfileEmail#</a></p></cfif>
    									
    												</div>
    												<cfif LEN(#staffProfileImage#)>
    													<div class="staffImage">
    														<cfif LEN(staffProfileImage) AND fileExists(APPLICATION.siteFilePath & "contentFiles\components\twStaffProfiles\" & REQUEST.instanceId & "\" & staffProfileImage)><img src="contentFiles/components/twStaffProfiles/#REQUEST.instanceId#/#staffProfileImage#" width="100" height="120" alt="#staffProfilePosition#">
    														</cfif>
    													</div>
    												</cfif>
    											</cfif>
    										
    										</li>
    									</ul>
    								</cfoutput>
    							</cfloop>
    						<cfelse>
    							<cfoutput>
    								<p>There are Currently No Staff Listed in this Department</p>
    								<br>
    							</cfoutput>
    						</cfif>
    						</cfoutput>
    				<!---end loop one--->	
    	</cfloop>
    </cfif>

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,446
    Thanks
    13
    Thanked 361 Times in 357 Posts
    looks like you want to access an element, that’s not been created yet.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That div will be rendered when the page loads,
    and the script would only fire once clicked on no?

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,446
    Thanks
    13
    Thanked 361 Times in 357 Posts
    I’ve never done things in CF, but the error message is typical for that kind of problem. the other kind is, you don’t have an element with that ID (you have an element with that class, but that doesn’t count)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #6
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay,

    Problem solved, I was defining the Div by Class, and not by ID.
    I need coffee!

    Many thnaks for the input Dormilich.

    EDIT: Just reloaded this page when I posted, and sawe your new post. yep, you got it spot on Dormilich, that was the problem
    Thanks again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •