i think i understand what happens, but i'm not really happy about it. The reason it works is you call the function right after you declare it. I guess this is kind of a substitute for the ajaxonload function. My problem is, i don't want the function to execute onLoad, because it needs some user selected values from the form, to pass as parameters to the cfc
if i do the same thing (call the function after declaring it), i get another "Null" error, this time about the form fields that haven't been set by user yet. after that, the function will work
can i prevent it from executing onLoad?
thanks again
ion wrote: can i prevent it from executing onLoad? |
Hi ion,
You're welcome, and yes. Can you please try this:
Application.cfc
----------------------
component {THIS.name = "TestCFAjaxproxyCFC";}
text.txt
----------------------
my text
MyCFC.cfc
----------------------
component {remote string function myCFCFunction(required string myArg) {return fileRead(expandPath("./text.txt")) & '-' & ARGUMENTS.myArg;}}
index.cfm
----------------------
<cfajaxproxy cfc="MyCFC" jsclassname="myCFCJSObj" />
<script type="text/javascript">
function myCallbackHandler(result) {
alert(result);
}
function myErrorHandler(statusCode, statusMsg) {
alert('Status: ' + statusCode + ', ' + statusMsg);
}
function myJSFunction() {
var instance = new myCFCJSObj();
instance.setCallbackHandler(myCallbackHandler);
instance.setErrorHandler(myErrorHandler);
instance.setReturnFormat('plain');
instance.myCFCFunction(document.getElementById("myfield").value);
}
//myJSFunction();
</script>
<cfform>
<cfinput type="text" name="myfield" value="foobar" />
<cfinput type="button" name="mybutton" value="submit" onclick="javascript:myJSFunction()" />
</cfform>
Clicking 'submit' should alert "my text-foobar".
Thanks,
-Aaron