Ok this is the main page which grabs the items from a database using the a PHP object previously defined ($battle).
PHP Code:
if($batt["playerstage$battle->userplayer"]=='TURN'){
$battle->location='HAND';
$yours=$battle->getallcards();
echo"<div id='ajaxDiv'>";
while($yourhand=mysql_fetch_array($yours)){
$name=$battle->getdetails($yourhand[cardid]);
echo"<form name=hand><input type=hidden name=cid value=$yourhand[ID]><input type=button name='card' value='$yourhand[ID]' onclick='ajaxFunction();'></FORM>";
}
if ($battle->count>'7'){echo"<br>You can only have 7 cards in your hand at any one time.";}
}
echo"</div>";
?>
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
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;
}
}
}
// 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", "discardcard.php", true);
ajaxRequest.send(null);
}
//-->
</script>
The deleteitem.php page looks like this
PHP Code:
<?php
include"cards2.php";
$b=rand(1,100);
echo"Card Discarded $b";
$battle=new battle;
$battle->ucardid='1';
$battle->location='DECK';
$battle->movecard();
$battle->location='HAND';
$yours=$battle->getallcards();
echo"<div id='ajaxDiv'>";
while($yourhand=mysql_fetch_array($yours)){
$name=$battle->getdetails($yourhand[cardid]);
echo"<form name=hand><input type=hidden name=cid value=$yourhand[ID]><input type=button name='card' value='$yourhand[ID]' onclick='ajaxFunction();'></FORM>";
}
if ($battle->count>'7'){echo"<br>You can only have 7 cards in your hand at any one time.";}
echo"</div>";
?>
<html>
<body>
This works in that onclicking a button it deletes the item from the database with id 1 per this line:
PHP Code:
$battle->ucardid='1';
What I want however is to pass a variable so that onclicking a specific button, it deletes that specific item.
Cheers
Bookmarks