Search code examples
javascriptcoldfusioncrudcfquerycfoutput

ColdFusion - approach for table of query data and CRUD actions


My question is more geared towards approach than it is programming or errors.

I have a query that runs and gathers a set of data. I then want to use that query's return values to build a table on a page listing all the values. Along with that I need to have some actions with each value for example:

my_val (edit) (delete)
my_cal (edit) (delete)

Where edit and delete are buttons. So the edit button I have working with onClick javascript, where i'm redirected to another page, but the delete button i need that to do three things:

  1. prompt user, okay to delete? msg (using javascript for that (return confirmation...).
  2. execute query to delete
  3. refresh page (self)

Is there a best approach model for this? Is it easier to call two inline javascript commands? Use javascript functions? Maybe a ColdFusion function?

any pointers would be helpful! thanks.


Solution

  • I think the easiest way for the delete is something like this. I do assume you use jQuery or some other library or get the JavaScript stuff.

    YourPage.cfm
    <cfif structKeyExists(URL, "Action") and URL.Action eq "delete">
        <cfququery>
           // delete the item using the id provided
        </cfquery>
    </cfif>
    
    <cfquery name="GetFresh">
        // get fresh info
    </cfquery>
    
    <cfloop query="GetFresh">
        Something <span class='DeleteLink' data-someid='#SomeID#'>delete</span> <br>
    </cfloop>
    
    <script type='text/javascript'>
    
        $DeleteLinks = $("span.DeleteLink");
    
        $DeleteLink.click(function() {
            var Confirm = confirm('Are you sure you want to delete?');
            if (Confirm == true) {
               var SomeID = $(this).data("someid");
               var URL = "YourPage.cfm?Action=delete&SomeID=" + SomeID;
               window.location = URL;
            }
        });
    </script>