Calling a coldfusion cfc on Blur with javascript or Jquery : (needs tweaking)

I am attempting to onblur: of a form field call a function that calls a cfc
and does an insert.

I have this:
Javascript:
<cfajaxproxy cfc="cfc/ZQuote" jsclassname="cfcZQuote" />
<script language="javascript">
function fastData(name, lname, phone1,phone2,phone3,email){
 var proxy = new cfcZQuote();
proxy.AddData(name,lname,phone1,phone2,phone3,email)
}
</script>


This form field.


<input name="email" type="text" id="email" class="menu" size="20" onblur="return fastdata(this.form.firstname,this.form.lastname,this.form.phone1,this.form.phone2,this.form.phone3,this.form.email);">

this is mY cfc:

<cfcomponent name="ZQuote" displayname="ZQuote" >
      <cffunction name="AddData" access="remote" output="no" returntype="struct">
                          <cfargument name="name" type="string" required="yes" />
                          <cfargument name="lname" type="string" required="yes" />
                          <cfargument name="Phone1" type="string" required="yes" />
                         <cfargument name="Phone2" type="string" required="yes" />
                        <cfargument name="Phone3" type="string" required="yes" />
                        <cfargument name="email" type="string" required="yes" />
            
            <cfset var returnStruct = StructNew()>
            <cfset returnStruct.agentID = arguments.name>
            <cfset returnStruct.Phone = arguments.Phone1 & arguments.Phone2 & arguments.Phone3 >
            <cfset returnStruct.uniqueID = "">
                  <!--- Update db with new data--->
<cfquery name="The_Query" datasource="#db#">
INSERT INTO Table      
                (name,lastname,phone)
                Values ('#returnstruct.name#','#returnStruct.lname#','#returnstruct.phone#'
                        SELECT SCOPE_IDENTITY() as ID
                  </cfquery>
</cfif>                  
                  <cfset returnStruct.uniqueID = The_query.id>

            

            <cfreturn returnStruct>
      </cffunction>
   
    </cfcomponent>
LeadCoAsked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
>> return fastdata(this.form.firstname,  this.form.lastname

You're passing in the form field objects NOT their values  ie this.form.firstname.value
0
 
leakim971PluritechnicianCommented:
Could you post a generated page ?
(right click on the page in the browser and choose : view source)
0
 
LeadCoAuthor Commented:
argumentCollection={"name"%3A{}%2C"lname"%3A{}%2C"Phone1"%3A{}%2C"Phone2"%3A{}%2C"Phone3"%3A{}%2C"email"%3A{}}&_cf_nodebug=true&_cf_nocache=true&_cf_rc=0

Ok looks like the form values are coming across.

hmmm ... any suggestions how to pass a collection of form values through the function() on blur of 1 field.

<input name="email" type="text" id="email" class="menu" size="20" onblur="return fastdata(this.form.firstname,this.form.lastname,this.form.phone1,this.form.phone2,this.form.phone3,this.form.email);">
0
 
_agx_Commented:
... that submitted before I was finished.

I meant to say pass in the value:  

      this.form.firstname.value  

... _not_ the object
        this.form.firstname



0
 
reitersConnect With a Mentor Commented:
Here is the jQuery way of doing it.  Make sure you have jQuery loaded on the page.  Remember that variables are case sensitive.

IF using jQuery, then you wont need any of the cfajaxproxy stuff. Also the onBlur ont he form field would be removed.  If the <script> is inside a cfoutput, make sure you change the # to ##
<script type="text/javascript">
   $("document").ready(function(){
      $("#email").blur(function(){
         $.ajax({
            url: 'cfc/ZQuote.cfc?method=AddData&name=' + $("#name").val() + '&lname=' + $("#lname").val() + '&Phone1=' +$("#Phone1").val()  + '&phone2=' + $("#phone2").val() + '&Phone3=' + $("#phone3").val() + '&email=' +$("#email").val() ,
            cache: false,
            success: function(){
               // anything u want to happen after the cfc call
               };
            });
         });
      });
</script>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.