Solved

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

Posted on 2010-08-17
2
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

726 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