Hi have this piece of code to display images of cameras and a caption underneath which states what type of camera it is. However I cant get the caption to change, i posted this piece of code before and some responded stating i need to '==' not just one. I have done that and it still isnt working. Anyone else have any idea? should it be cameraImage im comparing to the filename or should it be something else.
<script type="text/javascript">
function showImage(imageFileName)
{
// get image element
var theImageElement = document.getElementById("cameraImage");
// change what image is displayed
theImageElement.src=imageFileName;
if(cameraImage == "Canon_20d.jpg")
{
document.getElementById("imageCaption").innerHTML = "Canon 20d";
}
else if(cameraImage == "Fuji_s3Pro.jpg")
{
document.getElementById("imageCaption").innerHTML = "Fuji S3 Pro";
}
else if(cameraImage == "Fuji_9500.jpg")
{
document.getElementById("imageCaption").innerHTML = "Fuji 9500";
}
else (cameraImage == "sony_r1.jpg")
{
document.getElementById("imageCaption").innerHTML = "Sony r1";
}
}
}
</script>
</head>
<body>
<div id="mainContainer">
<div id="topSection">
<h1 style="text-align:center; padding-top:20px">COM301 Recipe 7: Camera e-commerce site</h1>
</div>
<div id="contentWrapper">
<div id="contentLeft">
<p style="text-align:center">Useful Links</p>
<br />
<a href="http://www.google.com">Click here for Google</a>
<br />
<a href="http://www.bbc.co.uk">Click here for BBC</a>
<br />
</div>
<div id="contentRight">
<div style="float:right; margin-top:5px; margin-right:5px">
<img id="cameraImage" src="blank.jpg" /> <br />
<div style="text-align:center" id="imageCaption"> No Image</div>
</div>
<?php
// open a file for reading
$fp = fopen("cameras.txt", "r");
if ($fp != FALSE) {
// set up the table for structured output
echo "<table border='2' width='75%' rows='4'>";
echo "<tr><th>Make</th><th>Model</th><th>Price</th><th>Rating</th><th>Stock</th><th>Image</th></tr>";
// read the data line by line
while (($buffer = fgets($fp)) != FALSE) {
// extract the component parts of the line
// remove whitespace
$buffer = trim($buffer);
$data = explode(',', $buffer);
// display the data
echo "<tr><td align='center'>$data[0]</td>
<td align='center'>$data[1]</td>
<td align='center'>$data[2]</td>
<td align='center'>$data[3]</td>
<td align='center'>$data[4]</td>
<td align='center'><input type='button' value='Image' onClick='showImage(\"$data[5]\");'/></td></tr>";
}
// close table
echo "</table>";
// close the file
fclose($fp);
}
?>
</div>