Javascript HTML - tilføj billede til td ved onclick
Der, hvor jeg har lavet et X, vil jeg gerne have, at man kan trykke, og der skal derefter uden loading bare komme et billede in i cellen.Og det er iøvrigt en chat :-)
chat.php
<?php
include('configuration.php');
// vars used to set tables size
$vertical_slots = 4;
$horizontal_slots = 6;
$max_slots = $vertical_slots*$horizontal_slots-1;
if(isset($_SESSION['username'])) {
$td = "width=\"70px\" height=\"80px\" align=\"center\" valign=\"bottom\"";
$defined_field = array(); // Defines the array
$query = mysql_query("SELECT * FROM 2d_chat_room_1");
while($row = mysql_fetch_assoc($query))
{
$time_now = time();
$users_time = $row['timer'];
$latency = ($time_now-$users_time)*10;
if($latency < 100) {
$defined_field[$row['slot']] = "<img src=\"{$row['figure']}\"><br><b><font color=\"white\"><a href=\"profile.php?username={$row['username']}\" target=\"right_page\">{$row['username']}</a></font>"; // Adds name to slot
}
}
// Starts table outside the for-loop
echo "<table CELLPADDING=\"0\" CELLSPACING=\"0\" background=\"backgrounds/1.png\">";
echo "<tr>"; // TR OPEN
for($i=0; $i <= $max_slots; $i++) {
if($i % $horizontal_slots == 0) { // end row and start new at every 5th td
echo "</tr><tr>"; // TR END TR OPEN
}
if(isset($defined_field[$i])) { // if slot is already defined/taken
echo "<td {$td}>";
echo "{$defined_field[$i]}";
}
else { // slot is empty
echo "<td {$td} onclick=\"parent.felt.location='goto.php?f={$i};'\">X";
}
echo "</td>";
}
echo "</tr>"; // TR END
echo "</table>";
// Ends table outside for-loop
function check_online() {
// Tells the database that, user is still on (add a new timestamp)
$time = time();
mysql_query("UPDATE 2d_chat_room_1 SET timer = '{$time}' WHERE username='{$_SESSION['username']}'");
}
check_online();
}
else {
echo "Please <a href=\"index.php\">login</a>, to use the chat!";
}
?>