It could be done using JS, but there would be no way of getting the actual data to you. You would need either server side scripting or an outside service to email the results to you.
If there is only one choice the user has when selecting an image (ie, they click an image, and you get told which image is clicked) then you don't even need to use JavaScript.
If the user can select multiple images and then submit them as a list or w/e, then JS is the best way here.
If you only need the one image, you can use PHP in addition to your HTML image.
In the page with the images, use this code for each image:
Code:
<a href='results.php?image=1' border='0'><img src='picture1.png' alt='1st picture'></a>
Yes, it's just a picture link to a PHP page.
Next, create a new file in the same directory called
results.php.
In it, put this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Image Selected.</title>
</head><body>
<p>
<?php
if (isset($_GET['image']))
{
$fh = fopen("choices.inc", 'a') or die("can't open file");
fwrite($fh, '<?php $images[] = '."'".$_GET['image']."'; ?>\n");
fclose($fh);
echo "Thank you for your selection";
}
else echo "Something funny happened, no data saved :)";
?>
</p></body></html>
Save it, then create a new file called
viewresults.php
In it, put this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Results Page</title>
</head><body>
<?php
$images = array();
if (isset($_GET['code']))
{
if ($_GET['code'] == 'yoursecretpassword')
{
if (file_exists("choices.inc"))
{
require_once("choices.inc");
}
else echo "file not found! Any data saved?";
}
}
$results = array_count_values($images);
ksort($results,SORT_NUMERIC);
echo "<table border='1'><tr><th>Image<th>Times Selected";
foreach ($results as $key => $value)
{
echo "<tr><td>$key<td>$value";
}
echo "</table>";
?>
</body></html>
And save it. You're all done!
Now whenever you want to view the results, go to
http:
//yoursite.com/youdirectory/viewresults.php?code=yoursecretpassword
You will see the results in a table, with everything totalled up.
You should change the password, as well as the original HTML page with different values for the images in both the links and the actual image tags, and then you should find it works perfectly
(btw, it's untested, but should work)