Scenario :
I am populating an option select list dynamically from a MySQL Table. This option list will be created multiple times on a page.
(Example :
Code: Select all
<?php
$sql = "SELECT * from my_site";
$result = mysql_query($sql) or die(MySQL_Error());
while($row = mysql_fetch_assoc($result)) {
$name[] = $row['field_name'];
$value[] = $row['field_value'];
}
$i=0;
foreach($name as $field_name) {
if($field_name == 'color') {
echo '<select name="bob'.$i.'">';
foreach($value as $hex_color_code) {
echo '<option value="'.$hex_color_code.'">'.$hex_color_code.'</option>';
}
echo '</select> <input type="text" name="bobs_value'.$i.'">';
} else {
//do some other checks
}
}
?>Code: Select all
<select name="bob1">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
</select> <input type="text" name="bobs_value1">
.......some html
<select name="bob2">
<option value="#FFFFFF">White</option>
<option value="#000000">Black</option>
</select> <input type="text" name="bobs_value2">I kind of understand that this can be done using an OnChange even with javascript, but I have no clue as how to do this without effecting all the other text boxes and their values. Because as you can see, I will have multiple Color Selects within 1 page. So I need to figure out WHICH select box something was selected in, and then tell it the occompaning Text Box to populate the result into. If anyone can shed some light on this, it would be much appreciated.