Solved

CFdiv bind failed - element not found

Posted on 2012-04-11
14
867 Views
Last Modified: 2012-04-23
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

0
Comment
Question by:lantervj
  • 5
  • 5
  • 4
14 Comments
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 37839052
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>
0
 

Author Comment

by:lantervj
ID: 37842406
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.
0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 37845095
Does your code has cfajaximport tag ?

I do not see in the code above.



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

Expert Comment

by:Pravin Asar
ID: 37845103
May be use  cfdebug with url

http://localhost/code.cfm?cfdebug


That may help.
0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 37845119
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>
0
 

Author Comment

by:lantervj
ID: 37846421
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

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37871218
> 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" />
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:lantervj
ID: 37871377
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.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37871536
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>
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37871571
> 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.
0
 

Author Comment

by:lantervj
ID: 37871589
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').
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37871753
> 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?
0
 

Author Comment

by:lantervj
ID: 37871958
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"?
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 37872149
A field is an input tag used inside of a form.. <input type="text" name="company">

A variable is created using a CFSET

When you do a form post or form get a variable is created for each form tag either in the FORM scope of the URL scope.

You cannot use CFIF statement to test to see if a form field exists.  You can only test to see if the variable created exists after a POST/GET.   You have to use javascript to test to see if a form field exists because it doesn't actually exist until the page is drawn and it's placed on the page.


Bind is based on javascript and ajax calls and requires the physical form tag to exist so that when the user changes input on the page, the bind activates.   ColdFusion variables are long gone by the time the page is created.   If you do View-Source in your browser, you can see that a bunch of javascript has been created around the input tag and CFDIV (which becomes just a DIV).   The DIV changes content based on the changes to the tag.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fixing some Issues with regex again 9 21
need some regex help 15 23
cfchart display 12 91
Align a <div> to a table row 3 38
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now