3 Replies Latest reply on Jan 16, 2012 12:28 AM by Prasanth Kumar.S

    how to use coldfusion function in onfocus event ?

    Ali Parsa

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




      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#'

                          <cfif admin.recordcount gt 0>

                                    FALSE condition ( and return false )

                          <cfelse >

                                    true condition


        • 1. Re: how to use coldfusion function in onfocus event ?
          ilssac Level 5

          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.

          1 person found this helpful
          • 2. Re: how to use coldfusion function in onfocus event ?
            Ali Parsa Level 1

            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 ?

            • 3. Re: how to use coldfusion function in onfocus event ?
              Prasanth Kumar.S


                  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.

              1 person found this helpful