Link to home
Start Free TrialLog in
Avatar of lantervj
lantervjFlag for United States of America

asked on

CFdiv bind failed - element not found

I have a form with a cfdiv that is bound to two checkboxes.  The checkboxes are dynamically created based on a query and cfdirectory.  Everything works as expected unless the directory is empty and either of the checkboxes are not created.  I surrounded the cfdiv with a cfif isdefined but that doesn't seem to have an affect.  The bindonload is false but that doesn't seem to have an affect.  The checkboxes are cfparam'd but that doesn't seem to have an affect.  By data, I can cause one or the other or both of the bind errors to go away.

<cfquery name="team" datasource="#request.dsn#">
	SELECT * FROM QExecSearchCandidatesPanel WHERE search_number = #val(searchnum)# ORDER BY date_Turneddown desc,Date_Of_Placement desc,Date_Of_Face_To_Face desc,Date_Telephoned desc,Date_Of_Resume desc,Date_Interviewed desc 
</cfquery>
<cfparam name="SearchAttachmentCheckbox" default="0">
<cfparam name="AttachmentCheckbox" default="0">
<div name="candidatePDFdiv" style="font-size:10">
	<cfoutput>
	<table style="font-size:medium;">
		<tr>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				<h2>Search Forms </h2>
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
		<cfdirectory action="list" type="file" directory="#request.Controlpath#clientsearch\forms\" name="PDFSearchFormslist" />
		<cfloop query="PDFSearchFormslist">
			<tr>
				<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
				<td>
					<font color="blue">
					<cfinput name="SearchAttachmentCheckbox" type="checkbox" value="#request.Controlpath#clientsearch\forms\#name#" />
					#name#&nbsp;&nbsp;&nbsp;&nbsp; #dateformat(DateLastModified,"yyyy/mm/dd")# 
					</font>
				</td>
			</tr>
		</cfloop>
		<tr>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				<h2>Candidate Forms</h2> 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
		<tr>
			<td width="20">
				&nbsp;&nbsp;&nbsp; 
			</td>
			<td>
				Status 
			</td>
			<td>
				Indiv Numb 
			</td>
			<td>
				Name 
			</td>
			<td>
				Documents 
			</td>
		</tr>
		</cfoutput>
		<cfoutput query="team">
			<tr>
				<td>
				</td>
				<td>
					#team.Status# 
				</td>
				<td>
					#team.Individual_Number# 
				</td>
				<td>
					#team.full_name# 
				</td>
			</tr>
			<cfdirectory action="list" type="file" directory="#request.Controlpath#individuals\forms\#team.Individual_Number#\" name="PDFlist" />
				<cfloop query="PDFlist">
					<tr>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							<font color="blue">
							<cfinput name="AttachmentCheckbox" type="checkbox" value="#request.Controlpath#individuals\forms\#team.Individual_Number#\#name#" />
							<cfinput name="AttachmentCandidateNAme" type="hidden" value="#team.full_name#" />
							#name#&nbsp;&nbsp;&nbsp;&nbsp; #dateformat(DateLastModified,"yyyy/mm/dd")# 
							</font>
						</td>
					</tr>
				</cfloop>
			</tr> 
		</cfoutput>
	</table>
	<cfoutput>
	<cfif isdefined('AttachmentCheckbox') and isdefined('SearchAttachmentCheckbox')>
		<cfdiv name="CandidateEmailToClientdiv" bind="url:CandidateEmailToClientdiv.cfm?SearchAttachmentCheckbox={SearchAttachmentCheckbox}&AttachmentCheckbox={AttachmentCheckbox}&AttachmentCandidateNAme={AttachmentCandidateNAme@none}&searchnum=#searchnum#" bindonload="false" />
	</cfif>
</cfoutput>
</div>

Open in new window

Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Here is simple example showing how this works.


<!--- Must Import --->
<cfajaximport tags="cfform,cfdiv"/>

<cfform name="form1">
<cfinput type="checkbox" name="rad1" value="1" checked="false">Value 1
<cfinput type="checkbox" name="rad2" value="2" checked="false">Value 2
</cfform>

<cfdiv bindonload="false"    bind="url:ShowPage.cfm?option1={rad1.checked@click}&option2={rad2.checked@click}" ID="theDiv"
        style="background-color:##4499dd; color:##00000; width:600; height:400"/>



<!--- CODE:  ShowPage.cfm --->

<cfif #url.option1# eq true>
      <cfoutput>
      <h1>OPTION1 #url.option1# is checked</h1>
      </cfoutput>
</cfif>
<cfif #url.option2# eq true>
      <cfoutput>
      <h1>OPTION2 #url.option2# is checked</h1>
      </cfoutput>
</cfif>
Avatar of lantervj

ASKER

I'm not sure what you are telling me.  Use @click?  That's the default anyway.  The cfajaximports are being done.  This page is included on the main page.  The bind works so long as there is data to create the 2 checkboxes.
Does your code has cfajaximport tag ?

I do not see in the code above.



<!--- Must Import --->
<cfajaximport tags="cfform,cfdiv"/>
May be use  cfdebug with url

http://localhost/code.cfm?cfdebug


That may help.
Isdefined('AttachmentCheckbox')  will always return true, by the virtue of
<cfparam name="SearchAttachmentCheckbox" default="0">

Do you mean to use

<cfif isdefined('AttachmentCheckbox') and isdefined('SearchAttachmentCheckbox')>

<cfif (#AttachmentCheckbox# eq 1) AND (#SearchAttachmentCheckbox# eq 1)>

            <cfdiv name="CandidateEmailToClientdiv" bind="url:CandidateEmailToClientdiv.cfm?SearchAttachmentCheckbox={SearchAttachmentCheckbox}&AttachmentCheckbox={AttachmentCheckbox}&AttachmentCandidateNAme={AttachmentCandidateNAme@none}&searchnum=#searchnum#" bindonload="false" />

</cfif>

</cfif>
Yes, I have the cfajaximport tag.  Everything works if the 2 checkboxes are actually created.  It's when either of the checkboxes are not created that I get the error.

The only way I could get this to work is by adding a cfset inside both of the loops and checking for that prior to the cfdiv.

<cfquery name="team" datasource="#request.dsn#">
	SELECT * FROM QExecSearchCandidatesPanel WHERE search_number = #val(searchnum)# ORDER BY date_Turneddown desc,Date_Of_Placement desc,Date_Of_Face_To_Face desc,Date_Telephoned desc,Date_Of_Resume desc,Date_Interviewed desc 
</cfquery>
<div name="candidatePDFdiv" style="font-size:10">
	<cfset searchFormsCount = 0>
	<cfset candidatesFormsCount = 0>
	<cfoutput>
	<table style="font-size:medium;">
		<tr>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				<h2>Search Forms </h2>
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
		<cfdirectory action="list" type="file" directory="#request.Controlpath#clientsearch\forms\" name="PDFSearchFormslist" />
		<cfloop query="PDFSearchFormslist">
			<cfset searchFormsCount = 1>
			<tr>
				<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
				<td>
					<font color="blue">
					<cfinput name="SearchAttachmentCheckbox" type="checkbox" value="#request.Controlpath#clientsearch\forms\#name#" />
					#name#&nbsp;&nbsp;&nbsp;&nbsp; #dateformat(DateLastModified,"yyyy/mm/dd")# 
					</font>
				</td>
			</tr>
		</cfloop>
		<tr>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				<h2>Candidate Forms</h2> 
			</td>
			<td>
				&nbsp; 
			</td>
			<td>
				&nbsp;
			</td>
		</tr>
		<tr>
			<td width="20">
				&nbsp;&nbsp;&nbsp; 
			</td>
			<td>
				Status 
			</td>
			<td>
				Indiv Numb 
			</td>
			<td>
				Name 
			</td>
			<td>
				Documents 
			</td>
		</tr>
		</cfoutput>
		<cfoutput query="team">
			<tr>
				<td>
					<!--- <cfinput name="CandidateEmailcheckbox" type="checkbox" value="#team.Individual_Number#" /> --->
				</td>
				<td>
					#team.Status# 
				</td>
				<td>
					#team.Individual_Number# 
				</td>
				<td>
					#team.full_name# 
				</td>
			</tr>
			<!--- <cfdiv bind="{CandidateEmailcheckbox@click}" bindonload="false"> --->
			<!--- <cfdirectory action="list" directory="#request.Controlpath#individuals\forms\#team.Individual_Number#\" name="PDFlist" /> --->
			<cfdirectory action="list" type="file" directory="#request.Controlpath#individuals\forms\#team.Individual_Number#\" name="PDFlist" />
				<cfloop query="PDFlist">
					<cfset candidatesFormsCount = 1>
					<tr>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							&nbsp; 
						</td>
						<td>
							<font color="blue">
							<cfinput name="AttachmentCheckbox" type="checkbox" value="#request.Controlpath#individuals\forms\#team.Individual_Number#\#name#" />
							<cfinput name="AttachmentCandidateNAme" type="hidden" value="#team.full_name#" />
							#name#&nbsp;&nbsp;&nbsp;&nbsp; #dateformat(DateLastModified,"yyyy/mm/dd")# 
							</font>
						</td>
					</tr>
				</cfloop>
			</tr> 
		</cfoutput>
	</table>
	<cfoutput>
	<cfif searchFormsCount and candidatesFormsCount>
		<cfdiv name="CandidateEmailToClientdiv" bind="url:CandidateEmailToClientdiv.cfm?SearchAttachmentCheckbox={SearchAttachmentCheckbox@click}&AttachmentCheckbox={AttachmentCheckbox@click}&AttachmentCandidateNAme={AttachmentCandidateNAme@none}&searchnum=#searchnum#" bindonload="false" />
	</cfif>
</cfoutput>
</div>

Open in new window

> Everything works as expected unless the directory is empty and either of the checkboxes are not created.

lantervj,

You actually never said what problem you're experiencing - just that it not working

> Everything works if the 2 checkboxes are actually created.  It's when either of the checkboxes are not created that I get the error.

Here you mention you get an error... what is the error and which file is it in?


> bind="url:CandidateEmailToClientdiv.cfm?SearchAttachmentCheckbox={SearchAttachmentCheckbox}

In this line, the value "SearchAttachmentCheckbox" is referring to a form field with the name "SearchAttachmentCheckbox" ... I don't see that input tag (I assume it's a checkbox field) in your code.   You are in some places treating it like it's a variable, I would remove the IsDefined() statements.

You want something like this...

<cfinput type="checkbox" name="SearchAttachmentCheckbox" value=1>  Check me

<cfdiv name="CandidateEmailToClientdiv" bind="url:CandidateEmailToClientdiv.cfm?SearchAttachmentCheckbox={SearchAttachmentCheckbox}&AttachmentCheckbox={AttachmentCheckbox}&AttachmentCandidateNAme={AttachmentCandidateNAme@none}&searchnum=#searchnum#" bindonload="false" />
The title of this thread is "CFdiv bind failed - element not found".  I've shown the code and it shows 2 checkboxes being created if the cfdirectory yields a list of file names.  The original question is about the cfdiv bind.  If the checkboxes have not been created I get an error "bind failes - element not found".  In another post I say that I used a cfset inside of each of the cfloops for file names from the cfdirectory.  Then I use a cfif to check that both of those cfsets have been done before I do the cfdiv.

I guess the question is;  Why does a cfdiv give a bind error when the elements have been cfparam'd  and why does the cfif isdefined fail to stop the cfdiv if the elements have not been cfparam'd and not created.
Sorry, I must have done something stupid, I did a search on SearchAttachmentCheckbox in the search didn't come up with anything, but now I see it IS there, but not always.


When the directory doesn't find anything, then there are no checkboxes so the bind will fail because it doesn't exist.  The bind is looking for the input tag only, having a variable with the same name doesn't help with the binding.


A possible solution would be to create a hidden tag with the same name

If the directory list returns no recrods then create a dummy hidden field for the bind to use...

<cfif PDFSearchFormslist.recordCount eq 0>
    <cfinput name="SearchAttachmentCheckbox" type="hidden" value="">
</CFIF>
> Why does a cfdiv give a bind error when the elements have been cfparam'd  and why does the cfif isdefined fail to stop the cfdiv

Keep in mind that the bind is creating a javascript solution, there is nothing server side.  The bind-javsacript is seeking out a field with the name used in the bind, it isn't looking for variables.   So the input tag has to exist for the bind to work, that's why I am suggesting creating a hidden tag when you don't need the checkboxes.
I'm doing a similar thing by setting a variable to zero and inside the cfloop I set it to 1.  I test for (cfif variable eq 1) and if that is true then I do the cfdiv/bind.

I'm curious why the cfdiv executed if bindonload is false and the elements have not been param'd  When it is surrounded by cfif isdefined('attachcheckbox').
> I'm doing a similar thing by setting a variable to zero and inside the cfloop I set it to 1

Yes, I see that now in your 2nd example.  That should work and I think your post said that it does?

>  I'm curious why the cfdiv executed if bindonload is false and the elements have not been param'd  When it is surrounded by cfif isdefined('attachcheckbox').

What is the    isDefined("attachCheckBox")   testing for?  It is testing for the existance of a variable called attachCheckBox.   It isn't testing for the existance of a field.. the bind requires that a field be present.   In your second code you get around this by not doing the bind at all unless both sets of checkboxes exist.  

But what if only one set of the check boxes exist, you aren't going to do the cfdiv?
I really don't need the cfdiv unless both checkboxes exists.

What's the difference between "the existance of a variable" and "the existance of a field"?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial