...

View Full Version : Script not defined error



mercuryfrost
07-26-2010, 01:47 PM
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:

<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:

<a href="javascript:;" onclick="DC_ShowDeptStaff()" return false;>See All Staff in this Department</a>

Full code is:

<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

mercuryfrost
07-26-2010, 02:58 PM
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

<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>

Dormilich
07-26-2010, 03:07 PM
looks like you want to access an element, thatís not been created yet.

mercuryfrost
07-26-2010, 03:16 PM
That div will be rendered when the page loads,
and the script would only fire once clicked on no?

Dormilich
07-26-2010, 03:18 PM
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)

mercuryfrost
07-26-2010, 03:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum