0
我想知道如何從下拉框中獲取值,然後將此值粘貼到文本框中。 我正在使用HTML和PHP。如何從下拉框中獲取數值?
這是我的代碼。我做了Lucanos做的,但沒有奏效。
<html>
<body>
<title>Num One Website</title>
<? $con = mysql_connect("localhost", "username", "password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result1 = mysql_query("SELECT * FROM Students") ;
echo "<FORM>";
echo "<select id='userid' name='userid' onchange='this.form.elements['showuserid'].value=this.options[this.selectedIndex].value'>";
while($row1 = mysql_fetch_array($result1)) {
echo "<option value='".$row1['ID']."'>".$row1['ID']."</option>";
$count = $count + 1;
}
echo "</select>";
echo "</FORM>";
mysql_close($con);
?>
<form action="ConfirmEnter.php" method="post">
<p>
<input id="showuserid" name="showuserid" readonly="readonly" size=5/>
<input type="text" name="name" />
<input type="text" name="mt" size=5 value="0.0"/>
<input type="text" name="pr" size=5 value="0.0" />
<input type="text" name="fi" size=5 value="0.0" />
<input type="text" name="tot" size=5 />
</p><br><br>
<input type="submit" value="Submit" /><br>
</form>
</body>
</html>
心態表現出一定的代碼? – 2011-05-29 12:00:24
Lucanos代碼不適合你,因爲你將下拉標籤放在單獨的表單標籤中。它應該與showiserid字段的形式相同。 – IvanGL 2011-06-17 05:36:10