Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query database "onblur" of textbox

Explorer ,
Dec 10, 2010 Dec 10, 2010

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

3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Dec 10, 2010 Dec 10, 2010

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

...
Translate
Contributor ,
Dec 10, 2010 Dec 10, 2010

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2010 Dec 10, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 10, 2010 Dec 10, 2010

If you can display a message, you can take away the submit button.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 10, 2010 Dec 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 10, 2010 Dec 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2010 Dec 21, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2010 Dec 21, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 21, 2010 Dec 21, 2010

Thank you Dan that works a treat.. I wish I had thought of doing that.

Have a nice Christmas pal!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 23, 2011 Aug 23, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 24, 2011 Aug 24, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources