Copy link to clipboard
Copied
Hi All,
As the titles suggests I have a form field field called 'formref' which is a cfinput field and of type text. On blur or on leave of focus I would like to query a cfquery with the value of the textbox so I can see wether or not the user has entered a duplicate formref which already exists in the database and display the user a friendly error message to make them re-type another formref.
I am only getting back into coldfusion after many years out so would apprciate any help you guys can give ![]()
Many Thanks
George
Hi,
You can use jQuery for this.
or use Bind. For Bind here is the example
This is my cfm file, where I will take the input.
<cfform id="myForm" format="html">
This is my edit box.<br />
<cfinput type="text" name="myText">
</cfform>
<hr />
And this is the bound div container.<br />
<cfdiv bind="cfc:bindSample.getDivContent({myText})"></cfdiv>
I will get the user input here and just print it.
Here is the bindSample.cfc
<cfcomponent output="false">
<cffunction name="getDivCon
Copy link to clipboard
Copied
Hi,
You can use jQuery for this.
or use Bind. For Bind here is the example
This is my cfm file, where I will take the input.
<cfform id="myForm" format="html">
This is my edit box.<br />
<cfinput type="text" name="myText">
</cfform>
<hr />
And this is the bound div container.<br />
<cfdiv bind="cfc:bindSample.getDivContent({myText})"></cfdiv>
I will get the user input here and just print it.
Here is the bindSample.cfc
<cfcomponent output="false">
<cffunction name="getDivContent" returntype="string"
access="remote">
<cfargument name="edit">
<cfreturn "This is the content returned from the CFC for
the div, the calling page variable is '<strong>#arguments.edit#</
strong>'.">
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
Hi Thanks for your sugestion it works great, and I am succesfully displaying an error message to the user if it is a duplicate formref.
My only problem now is, how do I stop them from submitting the form if this error message exists ???
Copy link to clipboard
Copied
If you can display a message, you can take away the submit button.
Copy link to clipboard
Copied
Don't forget to check again when the page has been submitted to the server, you can't disable a submit button if the user has JS disabled.
Copy link to clipboard
Copied
Good suggestion, misleading explanation.
If the user has js disabled, the onBlur action would not have worked. However, since it's a textbox, it's usually possible to submit the form with the enter key. I don't know if this triggers the onBlur for that textbox or not. The OP might want to test it.
Copy link to clipboard
Copied
Guys still struggling with this.... I am displaying my message corerctly but I am struggling to utilize the return parameter on the parent page.
Here is what I have so far.
Parent Page
<cfinput id="formref" name="formref" type="text" title="Form reference" />
<cfdiv id="georgetest" bind="cfc:checkRef.getDivContent({formref})" bindonload="false"></cfdiv>
checkRef.cfc
<cfcomponent output="false">
<cffunction name="getDivContent" returntype="string" access="remote">
<cfargument name="edit">
<cfif len(arguments.edit) equals 11>
<cfquery name="checkFormRef" datasource="#application.dsn#">
SELECT applicationid
FROM safegrd_owner.application
WHERE formref = '#arguments.edit#' and rownum = 1
</cfquery>
<cfif checkFormRef.recordcount gte 1>
<cfreturn "<span style='color:red;font-weight:bold'> #arguments.edit# is already in use. Please enter another reference.</span>">
<cfelse>
<cfreturn "<span style='color:green;font-weight:bold'> #arguments.edit# is a valid form reference.</span>">
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Basically if, the reference is already in use then I want to disable a submit button on my parent page... if it is a valid reference then I will allow them to proceed and submit the form.
If you could help I would be very grateful, this is my first time getting back into cf for a ong while so I am a bit rusty.
Many Thanks,
George
Copy link to clipboard
Copied
What if you tried changing this:
<cfreturn "<span style='color:green;font-weight:bold'> #arguments.edit# is a valid form reference.</span>">
to this
<cfreturn "<span '><input type='submit'></span>">
It might not be completely userproof though. When you test it, change the textbox value to something invalid after you run the onBlur.
Copy link to clipboard
Copied
Thank you Dan that works a treat.. I wish I had thought of doing that.
Have a nice Christmas pal!
Copy link to clipboard
Copied
How would you do this in MX7. The cfc: way to invoke does not seem to work in MX7. I am trying fill a text box after
querying the database.
Copy link to clipboard
Copied
Put your coldfusion stuff in a template and put that template into an iframe of your main page. Use javascript to send data to the iframe page and to write back to the main page.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more