Solved

is it possible to pass data to an insert query in a cfc via javascript?

Posted on 2010-08-17
2
324 Views
Last Modified: 2012-05-10
Hi, I have a cfc page containing an insert statement to a db and on my cfm page, I have various javascript functions, one in which is a save() function. In this function, I want to pass data from my form via javascript to the insert query in my cfc. Is this possible? If so, how are there any examples?

I will be attaching a code snippet shortly cause I am currently away from my pc where the code resides. In the meantime, if someone could give me any examples or references that would be appreciated. Thanks.
0
Comment
Question by:grnmachine
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 500 total points
ID: 33456485
You can do this via an AJAX post to a remote function within your CFC.

Using a library such as jQuery will make this a 100 times easier. See below for some example code
/*AJAX call using Jquery*/

$.post("test.cfc?method=functionName", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });

/*Code in your CFC*/
<cffunction name="functionName" access="remote" output="no">     
<cfquery datasource="yourDatasource">
    INSERT INTO yourTable
    (Name, Time) VALUES (<cfqueryparam value="#FORM.name#" cfsqltype="cf_sql_varchar">,<cfqueryparam value="#FORM.Time#" cfsqltype="cf_sql_varchar">)
</cfquery>
<cfreturn "Inserted correctly">
</cffunction>

Open in new window

0
 

Author Closing Comment

by:grnmachine
ID: 33456826
Thanks, this works well.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 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