Basically, I am doing this: I have already read the database and obtained all the items, each includes a 'name' and a 'link'. On the page, I have an image, a select menu, and a button; each select option displays an item name (but no link information). I want to implement this: first select an option (nothing happen), and then click the button to change the image src to the selected item's link (in PHP variable). But I have trouble to pass the link to the javascript function, because it involves PHP variable. The code is like this:
<script type="text/javascript">
function selectItem(i) {
var name, link;
/*
...
*/
document.getElementById("name").innerHTML = name;
document.getElementById("pic").src = link;
}
</script>
...
<body>
<img id="pic" src="default.png">
<div id="name"></div>
<div onclick="location.href='javascript:selectItem(document.
getElementsByName("menu")[0].value)';"></div>
<select name="menu">
<option value="">select one</option>
<?php
$i = 0;
foreach ($items as $item):
echo ("<option value=\"" . $i . "\">" . $item['name'] . "</option>");
$i++;
endforeach;
?>
</select>
</body>
Thanks for helping!