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

how to use coldfusion function in onfocus event ?

Guest
Jan 12, 2012 Jan 12, 2012

Copy link to clipboard

Copied

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>

TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

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
Valorous Hero ,
Jan 12, 2012 Jan 12, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Guest
Jan 12, 2012 Jan 12, 2012

Copy link to clipboard

Copied

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 ?

Votes

Translate

Translate

Report

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 ,
Jan 16, 2012 Jan 16, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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
Documentation