I have a select tag that is populated with a list of files each time the page loads. I would like the image to change to the selected file each time one is clicked in the select input. This is what I have right now, and it does not work properly. However, when it is clicked, the image and text are visible/hidden as they should be. Any help would be greatly appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Table Edit The Shakespeare Studio </title>
<link rel="stylesheet" type="text/css" href="../styles.css" />
</head>
<body>
<script language="javascript" type="text/javascript">
function edit_image1()
{
if (document.getElementById('select1').value == "0") {
document.preview1.style.visibility = "hidden";
document.getElementById('random1').style.visibility = "visible";
} else {
var selected = document.getElementById('select1').options[document.getElementById('select1').selectedIndex].value;
document.preview1.style.visibility = "visible";
document.preview1.src = "../resources/uploads/"+selected;
document.getElementById('random1').style.visibility = "hidden";
}
}
</script>
<div id="everything">
<form action='tableEdit.php' method='GET'>
<table border='1' id='cal'>
<tr id='top'><td> Page Name </td><td> Image to Use </td><td> Preview </td></tr>
<tr>
<td> about </td>
<td>
<select name='aboutImage' id='select1' onchange='edit_image1()';>
<option value='0' selected> RANDOM IMAGE</option>
<option value='IMG_6027.JPG'>IMG_6027.JPG</option>
<option value='IMG_6032.JPG'>IMG_6032.JPG</option>
<option value='kissme-1.jpg'>kissme-1.jpg</option>
</select>
</td>
<td>
<img name='preview1' src='../resources/uploads/0'></img>
<h3 id='random1'> Random </h3>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>