Reputation: 21944
I have a stored procedure with a "selection" parameter
<cfstoredproc procedure="MyProcedure" datasource="MyDataSource">
<cfprocparam type="in" cfsqltype="cf_sql_integer" value="#selection#" null="no">
</cfstoredproc>
I have a select box where the user can select the box, and I would like to use jquery to "call" the stored procedure:
$(document).ready(function(){
$('#selectbox').change(function() {
// update my #selection# variable
// run the stored procedure again (the one above)
});
});
Is there a way to do this? I know it's mixing client and server side code but I can't refresh the page because there are multiple forms on the page...
Upvotes: 2
Views: 1323
Reputation: 2706
You'll need create a .cfm page with stored procedure in it and use an AJAX call to execute the stored proc.
storedProc.cfm
<cfparam name="URL.selection" />
<cfstoredproc procedure="MyProcedure" datasource="MyDataSource">
<cfprocparam type="in" cfsqltype="cf_sql_integer" value="#URL.selection#" null="no" />
</cfstoredproc>
$(document).ready(function(){
$('#selectbox').change(function() {
// update my #selection# variable
$.get("storedProc.cfm", { selection: $(this).val() } );
});
});
Upvotes: 2
Reputation: 2772
You will need to put your Stored Proc call into a seperate CFM file for your jquery to call. You can't reference back to the one called on your page.
Upvotes: 0
Reputation: 16945
$(document).ready(function(){
$('#selectbox').change(function() {
$.get('pathToYourStoredProcCFM.cfm?selectVal=' + $(this).val(), function (res) {
// if you need to handle the response to the stored proc
// on the client side (which was output in your CFM code), do so here
// (the response from CF is stored in the "res" variable)
});
});
});
Upvotes: 6