Skip to main content
Inspiring
December 10, 2010
Answered

Query database "onblur" of textbox

  • December 10, 2010
  • 2 replies
  • 3119 views

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

    This topic has been closed for replies.
    Correct answer meensi

    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>

    2 replies

    Participating Frequently
    August 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.

    Inspiring
    August 24, 2011

    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.

    meensiCorrect answer
    Inspiring
    December 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>

    _G_1Author
    Inspiring
    December 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 ???

    Inspiring
    December 10, 2010

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