let's say i'm generating some sort of html table (from mysql queried data) with a checkbox at each row with something like
$display_string = "<form action=\"delete.php\" method=\"post\">";
$display_string .= "<div><input type=\"button\" VALUE=\"Button1\"></div>";
$display_string .= "<div><input type=\"button\" VALUE=\"Button2\"></div>";
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr onmouseover=\"this.className = 'hlt';\" onmouseout=\"this.className = '';\">";
$display_string .= "<td class='blank'><input type=\"checkbox\" /></td>";
$display_string .= "<td class='data'>" . $row['first_name'] . "</td>";
$display_string .= "<td class='data'>" . $row['last_name'] . "</td>";
$display_string .= "<td class='data'><a href='" . $row['email'] . "'>" . $row['email'] . "</a></td>";
etc...
etc...
$display_string .= "</form>";
what i'd like to happen now, after various checkboxes are selected are two things: 1) for example, call delete.php when Button1 is clicked to delete the selected rows. 2) some other php file called when Button2 is clicked
I have access to $row['ID'] which I can use to name each checkbox, i'm just not sure how to incorporate it since i'm new to php
UPDATE The following seems to work for my purposes
I've got the following html-
<form name='myForm' method=\"post\" >
<input type=\"submit\" onClick=\"deleterow(document.myForm)\" VALUE=\"Delete ROWs\">
while($row = mysql_fetch_array($qry_result)){
<input type=\"checkbox\" name='rows' value=" .$row['ID']. "/>
Javascript is as follows-
<script language=\"javascript\" type=\"text/javascript\">
function deleterow(form){
if (!confirm(\"Are you sure you want to delete?\")) return false;
var queryString = \"?ID=\";
for (var i = 0; i < document.myForm.rows.length; i++) {
if (document.myForm.rows[i].checked) {
ID = document.myForm.rows[i].value;
ID = ID.slice(0, -1);
queryString += ID;
queryString += \"-\";
}
}
queryString = queryString.slice(0, -1);
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\");
} catch (e) {
try{
ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");
} catch (e){
// Something went wrong
alert(\"Your browser broke!\");
return false;
}
}
}
var ajaxRequest; // The variable that makes Ajax possible!
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open(\"GET\", \"delete_row.php\" + queryString, true);
ajaxRequest.send(null);
confirm('Delete successful!');
}
then with delete_row.php you can do all you need to with a mysql query, and new data can be sent back and displayed with
<div id='ajaxDiv'></div>