Hi,
I’m populating a select list from a mySQL database like so :-
<?
// Populate Type List Box with up to date Equipment Types
$sql = “SELECT * FROM types ORDER BY type ASC”;
// execute SQL query and get result
$sql_result = mysql_query($sql,$dbcnx)
or die(“Couldn’t execute query.”);
// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$type = $row[“type”];
$typedesc =$row[“typedesc”];
$option_block .= “<OPTION value=\”$type\“>$typedesc</OPTION>”;
}
?>
<SELECT name=“selecttype” id=“selecttype”>
<? echo “$option_block”; ?>
</SELECT>
What i’d like to know is how i can set my field type = to the value of the selected item in the select list.
For example : i select the item ‘Electrical Motors’ from the list, the value of this is ‘ecm’ - i need to store that value in the field named type in mysql table.
I’m getting confused as i thought u get the value using Java Script and am not sure of the best way or when to break out of php and javascript etc.
Would i be right in saying it’s somthing like this :-
$type =?><script>document.theform.selecttype.value</script><?;
That doesn’t work obviously… but i’m trying
This is probably pretty simple, but i’d really appreciate it if someone could give me an example please?
Thanks in advance