Solved

CF call function onClick event

Posted on 2010-08-16
3
2,254 Views
Last Modified: 2013-12-24
Hi Experts,
After click on the button, nothing happens, only a sign on the bottom left corner of the page indicating an error on the page and saying Object expected.
Here is a simple code:

<cffunction name="updSchool" >
      <cfargument name="schName" type="string" required="yes">
       <cfquery name="NewSchool" datasource="#datasource#">
              INSERT INTO SCHOOLS (NAME)
            VALUES     ('#schName#')
          </cfquery>

</cffunction>

<cfform name="New">
        Name: <cfinput name="schname" type="text" value="" id="schname"><br>
      <cfinput type="button" value="Add Name" onclick="updSchool('schname';)" name="add"><br>
</cfform>
What am i missing? Please help.
Thank you.
0
Comment
Question by:kqureshi321
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
Comment Utility
The onClick is on browser side and the cffunction is on server side.
You can call server functions only by AJAX.

Check better this:

     <cffunction name="updSchool" >
      <cfargument name="schName" type="string" required="yes">
       <cfquery name="NewSchool" datasource="#datasource#">
              INSERT INTO SCHOOLS (NAME)
            VALUES     ('#schName#')
       </cfquery>
     </cffunction>

<cfform name="New">
        Name: <cfinput name="schname" type="text" value="" id="schname">
      <cfinput type="submit" value="Add Name" name="add"><br>
</cfform>

<cfif isDefined("FORM.add") >
  <cfoutput>
    Upadated: #updSchool(FORM.schname)#
  </cfoutput>
</cfif>

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
But beside that you will have a long way to make your funaction working: you do not return a result and you name you column Name. That is not the best choice.

0
 

Author Comment

by:kqureshi321
Comment Utility
thank you for the response.
I tried a function with a returning result and the name of the column not Name, i just put it there for example.
I want to try to use a SP instead of function.
Thanks anyway. I really appreciate it.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now