Skip to main content
Participant
December 7, 2006
Answered

Delete rows via checkbox

  • December 7, 2006
  • 3 replies
  • 561 views
Does someone have a sample code of how to delete rows via checkbox on a display page?

Thanks.

Best,

Manuel
    This topic has been closed for replies.
    Correct answer
    <cfform>
    <cfoutput query="name">
    <cfinput type="checkbox" value="#id#" name="myID">
    </cfoutput>
    </cfform>

    <cfquery datasource="name" name="myQuery">
    SELECT columns FROM table WHERE ID IN(#FORM.myID#)
    </cfquery>

    3 replies

    Correct answer
    December 8, 2006
    <cfform>
    <cfoutput query="name">
    <cfinput type="checkbox" value="#id#" name="myID">
    </cfoutput>
    </cfform>

    <cfquery datasource="name" name="myQuery">
    SELECT columns FROM table WHERE ID IN(#FORM.myID#)
    </cfquery>
    _mslima_Author
    Participant
    December 8, 2006
    Maybe I'm doing something wrong here. Would really appreciate any help. This is my code on the display page:

    --
    <TABLE>
    <CFLOOP QUERY="get_all_projects" StartRow="#URL.StartRow#" ENDROW="#EndRow#">
    <CFOUTPUT>
    <TR bgcolor="##dfdfdf">
    <TD bgcolor="##e5e5e5">
    <INPUT TYPE="checkbox" NAME="recdelete" VALUE="#id#">
    </TD>
    <td bgcolor="##ffffff"><span class="body_text">#input#</span></td>
    <td bgcolor="##f1f1f1"><span class="body_text">#DateFormat(date, "dd/mm/yyyy")#</span></td>
    <td bgcolor="##ffffff"><span class="body_text">#name#</span></td>
    </TR>
    </CFOUTPUT>
    </CFLOOP>
    </TABLE>

    <br />
    <cfform action="input_test.cfm">
    <input type="submit" value="Delete">
    </cfform>
    --

    Basically a loop displaying all rows and respective check-boxes.

    On "input_test.cfm" I'm only testing if I can retrieve the values for "recdelete":
    --
    Sucess
    <cfoutput>
    #FORM.recdelete#
    </cfoutput>
    --

    Which so far I wasn't able to.

    Maybe it's easier then it seems, but I'm not able to pass the "FORM.recdelete" variable to later delete de rows.

    Thanks in advance.

    Best,

    Manuel
    Inspiring
    December 8, 2006
    The checkboxes need to be inside the <FORM></FORM> or (<CFFORM></CFFORM>) tags in order to be passed via CGI to the processing page.
    Inspiring
    December 8, 2006
    Assuming you have a unique record ID for each row, you can display a checkbox:

    <INPUT TYPE="checkbox" NAME="recdelete" VALUE="#recID#">

    When the user submits the form, if any of the boxes are checked you'll have a value Form.recdelete that will have a comma delimited list of record IDs (such as 1404,1875,2060,3191). You can use this list in a SQL WHERE clause to select records for deletion.