since i've been looking into using ajax lately, i wanted to put together my first pages using prototype
but i'm kinda stuck.
situation:
i got a list of pages in the backoffice. in the list you got pagenames, id's, editors and if they're active or not. the active part part is represented by an in/active image.
now instead of having to edit the page and change a checkbox to toggle the active status of the page, i was planning to make it able to click on the image in the list itself to toggle the status of the page. thus updating the db when you clicked and refresh the list using ajax.
i got some code together, but i'm not sure how to handle things going from here...
here's my pages.php with the list of pages
<script>
function toggleActive(setToggle,id)
{
var url = 'pages/processor.php';
var pars = 'action=' + setToggle +'&id='+id;
var myAjax = new Ajax.Updater(
{success: 'placeholder'},
url,
{
method: 'get',
parameters: pars,
onFailure: reportError
});
}
function reportError(request)
{
alert('Sorry. There was an error.');
}
</script>
<?php
dbConnect();
$query = "SELECT id, text, active FROM test_pages";
$result = mysql_query($query);
?>
<table cellpadding="5" width="100%">
<?php
while ($row = mysql_fetch_array($result)) {
$text = $row["text"];
$id = $row["id"];
$active = $row["active"];
echo "<tr>";
echo "<td>id</td><td>active</td><td>text</td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$id."</td>";
if ($active =="1"){
$setToggle = "setinActive";
}
else {
$setToggle = "setActive";
}
echo "<td><a href=\"\" onclick=\"toggleActive(".$setToggle.",".$id.");\"><img src=\"images/nonactiefIcon.gif\"></a><br> ".$active."</td>";
echo "<td>".$text."</td>";
}
?>
</table>
and here's my processor.php which should be handling the request
<?php
$id = $_REQUEST['id'];
switch($_REQUEST['action']) {
case 'setActive':
echo "done";
$query=" UPDATE test_pages SET active = '1' WHERE id = $id";
mysql_query($query);
break;
case 'setInactive':
echo "done";
$query=" UPDATE test_pages SET active = '0' WHERE id = $id";
mysql_query($query);
break;
end switch
}
?>
i know my pages code/js isn't full complete, but that's where i could use some help..if possible.
thanx!