まあ、いくつかの方法でそれを行うことができます:
1) すべての要素を同じ形にする。各チェックボックスに同じ名前を付けますが、各チェックボックスに、それが表すレコード/ID/ファイルを区別する値を付けます。ブラウザーが準拠している場合は、フォームを送信すると、CGI アプリは HTTP パラメーターを POST または GET 送信の一部として表示できるはずです。PHP などの多くの CGI アプリケーションは、同じ名前のパラメーターを配列に結合します。C を使用していつでも param リストを自分で操作することもできます。
// Client side html
<table>
<form>
<tr><td><input type="checkbox" name="id" value="1"/></td><td>Row 1</td></tr>
<tr><td><input type="checkbox" name="id" value="2"/></td><td>Row 2</td></tr>
<tr><td><input type="checkbox" name="id" value="3"/></td><td>Row 3</td></tr>
<tr><td><input type="checkbox" name="id" value="4"/></td><td>Row 4</td></tr>
</form>
</table>
// Server side CGI, using pseudo-code
String[] ids = request.getArrayOfParametersNamed("id");
if(!empty(ids)) {
for(id in ids) {
DatabaseControllerModelThingWhatever.deleteById(id);
}
// Actually if SQL based you should use a batch statement instead of
// one-at-a-time deletes like above
}
// Ok the rows are deleted, either print out the page, or better yet,
// send a redirect so that a user-refresh does not try and re-delete
// already deleted stuff and also give the user a wierd "resubmit form" warning
// Done
2) AJAX と、できれば Javascript ライブラリのいくつかのタイプを使用して、ユーザーが [削除] をクリックすると、チェックされたレコードを削除する要求を送信する ajax ベースの送信を実行します。同時に Javascript を使用して、HTML テーブルから行を削除します。これは、ユーザーのページが完全に更新されないことを意味します。
// Client side HTML is same as before, only this time there is a DELETE button with
// an onclick handler. Also, add a "class" or "id" to each "tr" so we can find it
// in the HTML table
// Pseudo-javascript because I am lazy
function onDeleteButtonClick() {
// Get our ids
var idElements = document.getElementsById("id");
// Submit an async AJAX request (e.g. use Jquery and send ids as URL params)
ajaxedDeleteSubmission(idElements);
// Delete all the rows that should not be there
for(i = 0; i < tablex.rows.length; i++) {
// Grab the value of the "id" attribute of each table row (<tr id="?">...</tr>)
id = tablex.rows[id].id;
if(id in ids) {
// Remove the row, forget how because now I just use Jquery.
tablex.deleteRow(i);
}
}
}