I have a .cfc file and .cfm file. I want to call the function named "sendemail" located on the .cfc file and alert the user once the function completed successfully. I am using jquery so when the user click on the link, it will trigger this function.
This is what I have so far...
index.cfm file
<script>
$(document).ready(function(){
$(".forgot-pin").click(function(){
var getSchoolEmail = $("#schoolaccnt").val();
if (getSchoolEmail == '0'){
alert ("Please select school");
}else{
chkSchoolEmail = function(theAccNumber){
$.getJSON("/email.cfc",{
method:'sendemail',
accnumber: theAccNumber,
returnformat: 'json'
}, function(){
alert("Your PIN Number has been sent to your email address.");
});
}
}
});
</script>
<label>Please sign in below:</label>
<select id="schoolaccnt">
<option value="0">Select Your School</option>
<cfoutput query="get_schools">
<option value="#sch_id#">#sch_name#</option>
</cfoutput>
</select>
<span class="forgot-pin">Forgot PIN?</span>
email.cfc file
<cffunction name="sendemail" access="remote" returnformat = "json" >
<cfargument name="accnumber" required="true" type="string">
<cfset object = CreateObject("Component","cfobject")>
<cfquery name="get_schools" datasource="#dsn#">
SELECT sch_id,sch_name,sch_email_address,sch_pin_num
FROM DATABASENAMEHERE
WHERE sch_id = '#trim(accnumber)#'
</cfquery><!--- --->
<cfmail from="EMAIL" to=EMAILPULLEDOUTFROMDATABASE type="html" subject="Your PIN" >
Your PIN is <cfoutput>PINGOTFROMDB</cfoutput>
</cfmail>
<cfset result = 1>
<cfreturn object>
If the user does not know his/her pin, he/she selects from a dropdown and click on the "forgot pin" link and it should alert "pin sent to email address".
My problem:
The jquery is not calling the function. I am not sure if it is structured the correct way OR if I am missing something.
Any thoughts in solving this will be really appreciated!
*** EDIT ****
function sendMyPin(schoolaccnt){
var getschool = document.getElementById("schoolaccnt").value;
if (getschool == '0') {
alert("Please select school.");
} else {
DWREngine._execute("email.cfc", null, 'sendemail', getschool, getEmailResult);
}
function getEmailResult(emailObject){
alert('Your PIN has been sent to your e-mail.');
}
Now this is not working on CHROME!!! but works fine in IE and FF
The click handler is only defining a function chkSchoolEmail = function(theAccNumber){...}
. It does not call it.
$(".forgot-pin").click(function(){
var getSchoolEmail = $("#schoolaccnt").val();
if (getSchoolEmail == '0'){
alert ("Please select school");
} else {
$.getJSON("/email.cfc",{
method:'sendemail',
accnumber: theAccNumber,
returnformat: 'json'
}, function(){
alert("Your PIN Number has been sent to your email address.");
});
}
});