I am a total noob when it comes to javascript. I made parts of the script (onclick). And the Element id.
The probably is that the script is not changing the product picture on the page when a new color is selected.
Heres the code *brace yourself*
I think the problem is with the element id thing... where the src is... I don't think I put it in there correctly...PHP Code:<html>
<head>
<script type="text/javascript">
function myfunction(txt)
{
alert(txt);
document.getElementById("productpicture").src=(txt);
}
</script>
<!--The alert has told me that my function is correctly reading back. But it is not changing the image... -->
</head>
<body>
<?php
if(isset($_GET['id'])){
$con = mysql_connect("localhost","TOPSECRET","NOTHINGTOSEEMOVEALONG");
if (!$con)
{
include("error.php");// I need to make the error.php page
die('<br />Uh, there is a problem. The problem\'s error code is:' . mysql_error());
}
mysql_select_db("*IT WORKS*", $con);
$result = mysql_query("SELECT * FROM products WHERE id='$_GET[id]'");
while($row = mysql_fetch_array($result))
{
echo '<table id="spotlight"><tr><td colspan="3">';
echo $row['name'];
echo "</td>";
echo "</tr>";
echo "<tr>";
if(file_exists("pi/" . $row['id'] . ".png")){
echo '<td rowspan="5"><img src="pi/' . $row["id"] . '.png" /></td>';
}else{
echo '<td rowspan="5"><img src="pi/nopicture.png" id="productpicture" /></td>';
}
echo '<td colspan="2">' . $row["description"] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Size: </td>';
echo '<td>' . $row["size"] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Weight: </td>';
echo '<td>' . $row["weight"] . ' lb</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Price:</td>';
echo '<td>' . $row["price"] . '</td>';
echo '</tr>';
echo "<tr>";
echo '</table>';
echo '<table>';
echo '<tr>';
$colors = str_replace(", ",".png ",$row['colors']);
$newColors = explode(" ", $colors);
$countColors = count($newColors);// This works
$i = 0;
while($i<$countColors){
echo '<td>';
echo "<img src='pi/" . $row['id'] . "/" . $newColors[$i]. "' onclick='myfunction(\"pi/" . $row['id'] . "/" . $newColors[$i]. "\")' border='0'/>";
echo $newColors[$i];
echo '</td>';
$i++;
}
echo '</tr>';
echo '</table>';
}
mysql_close(); // But I want it open...
}
?>
</body>
</html>
Thanks for the help


Reply With Quote

Bookmarks