Skip to main content
January 12, 2012
Question

how to use coldfusion function in onfocus event ?

  • January 12, 2012
  • 1 reply
  • 1364 views

i have a username field in my form and i want to check the enter value on my database realtime to find if there is duplicate , can u please tell me how i can do it ?

<form name="login" action="savedata.cfm" >

     <input type="text" onfocus="call any coldfusion function " name="username">

</form>

i need the the function to be call inside from to check :

                <CFQUERY Name="admin" DATASOURCE="#request.tvgo_datasource#" USERNAME="#request.tvgo_db_username#" PASSWORD="#request.tvgo_db_password#">
                    select * from admin where username='#pass_value#'
                </CFQUERY>

                    <cfif admin.recordcount gt 0>

                              FALSE condition ( and return false )

                    <cfelse >

                              true condition

                   </cfif>

This topic has been closed for replies.

1 reply

ilssac
Inspiring
January 12, 2012

You can't actually use a ColdFusion function there.  ColdFusion runs on the server and only on the server.

The form is being used by a user on the client.  They only talk to each other via reqeusts and responses.

You CAN use a JavaScript function there.  Using AJAX (or other techniques) you can have the JavaScript function make a new request and get a response that is the result of your query.

CFML does have some wizard like tags that you can use to build your form field that will generate much, if not all, of that JavaScript AJAX functionality for you.

The documentation had entire chapters dedicated to descbing how to use those features of ColdFusion.

That is all that I have time to type before I need to go catch my train.

January 12, 2012

Ok , thanks man so i have a question :

i can do the validation in other page like validation.cfm , so i can pass the username to the javascript function, then script run the vlidation.cfm , this file has 2 answer , FALSE or TRUE.

now i want to know how can i run validation without change the page and return the resault to my function and if its false so the user can not submit form ?

Prasanth_Kumar_S
Inspiring
January 16, 2012

Hi,

    If you need to call a .cfm page without changing (posting) a page to server, you need to use AJAX. It is fairly simple if you use JS libraries like JQuery. You can try creating webservices in cf and call a function in it. For a function inside .cfc to be accessible as webservice, you need to make the access="remote" for the function.