Hi,
I have a form where the user can select a product and the product info will appear next to it.
The products and the data on them all come from a db so I needed it to be dynamically.
After a quick search in Google I found half answer - I managed to display the product data but if the user selected another product the previous product data stayed and more data appeared.
I need to know how I hide data when another product is selected.
Here is the code so far:
Thanks :)
I have a form where the user can select a product and the product info will appear next to it.
The products and the data on them all come from a db so I needed it to be dynamically.
After a quick search in Google I found half answer - I managed to display the product data but if the user selected another product the previous product data stayed and more data appeared.
I need to know how I hide data when another product is selected.
Here is the code so far:
Code:
<html>
<head>
<title>Test Form</title>
<script language="javascript">
function show(selObj) {
var selectedValue = selObj.options[selObj.selectedIndex].value;
document.getElementById(selectedValue).style.display = 'block';
}
</script>
</head>
<body>
<?php
$db = New DB;
$db->table="products";
$titles = $db->FetchTitles();
$titlesInfo = $db->Fetch();
?>
<form>
Select Product: <select id="products" name="MyProducts[]" onchange="show(this)">
<?php
foreach ($titles as $key => $value) {
print("<option value=\"$key\">$value</option>\n");
}
?>
</select><br />
<?php
foreach ($titlesInfo as $key => $value) {
print("<div id=\"$key\" style=\"display:none;\">");
foreach ($value as $keyf => $valuef) {
print($keyf . ": " . $valuef . " | \n");
}
print("</div>\n");
}
?>
</form>
</body>
</html>
Comment