我用我的数据库中的值制作了一个选择框,我想将所选项目的 ID 写入文本框。
怎么做到呢?我有这个代码..
<form method="POST" action="" id="submitKon">
<fieldset>
<table class="opretTable" border="0">
<tr>
<td width="180" height="30"><label for="valgtkon" class="labelLeft">Vælg konkurrencetype</label></td>
<td><select id="valgtTitel" name="valgtTitel" onchange="run()">
<?php
$virksomhedsID = $_SESSION['virkID'];
$sql = "SELECT * FROM konkurrenceType ORDER BY konkurrenceType.kontypeID";
$result = mysql_query($sql) or die(mysql_error());
echo '<option value="Vælg type">Vælg type</option>';
while($rowSelect = mysql_fetch_assoc($result))
{
echo '<option value="' . $rowSelect['kontypeID'] . '">' . $rowSelect['kontypeTitel'] . '</option>';
}?>
</select>
和..
<script>
function run() {
document.getElementById("valgtID").value = document.getElementById("valgtTitel").value;
}
</script>
我明白了
INSERT INTO `mah1233411190550`.`konkurrence` ( `konID` , `virkID` , `konTitel` , `konBeskriv` , `konMaal` , `konMaaltype` , `konStart` , `konSlut`, `kontypeID`, `holdID` ) VALUES (NULL , '1', '1', 'cykle', '500', 'km', '2013-01-01', '2018-05-03', '1', '' );
所以 konTitel 和 kontypeID 是一样的,这是为什么呢?