Php 将组合框html与文本字段同步
当我从组合框中选择一个菜单时,我正在尝试同步我的Php 将组合框html与文本字段同步,php,combobox,sync,textfield,Php,Combobox,Sync,Textfield,当我从组合框中选择一个菜单时,我正在尝试同步我的textfield: +---------+------------+ | class | name | +---------+------------+ | 10021 | John | | 10027 | Alex | | 10030 | Brian | | 10033 | Anita | +---------+------------+ 例如,当我从
textfield
:
+---------+------------+
| class | name |
+---------+------------+
| 10021 | John |
| 10027 | Alex |
| 10030 | Brian |
| 10033 | Anita |
+---------+------------+
例如,当我从组合框中选择
Alex
时,我的textfield
应显示值为10027
的字段,只需将while循环中的value=“.ri['name']更改为value=“.ri['class']
,
然后在更改选择框时使用
要使用JQuery更改文本框值
1)JQuery
<?
$cn=mysql_connect("localhost","root") or die("Note: " . mysql_error());
$res=mysql_select_db("psi",$cn) or die("Note: " . mysql_error());
$sql = "select name, class from list;";
$res=mysql_query($sql) or die("Note: " . mysql_error());
?>
<select name="names">
<?
while($ri = mysql_fetch_array($res))
{
//this comboBox works well
echo "<option value=" .$ri['name'] . ">" . $ri['name'] . "</option>";
}
echo "</select> ";
echo "Class :";
echo "<input disabled type='text' value=".$ri['class'].">". $ri['class'] . "</input>";
?>
也
echo”“$ri[“类”]。"";
到
回声“;
因为我们正在动态设置textbox值
2)Javascript:
echo "<input disabled type='text' value=".$ri['class'].">". $ri['class'] . "</input>";
to
echo "<input disabled type='text' value='' >";
选择一个值
巴文1
巴文2
巴文3
演示:而不是
<select onChange="document.getElementById('textbox1').value=this.value">
<option value=''>select a value</option>
<option value='bhavin1'>bhavin1</option>
<option value='bhavin2'>bhavin2</option>
<option value='bhavin3'>bhavin3</option>
</select >
<input type='text' id='textbox1'>
改为
<?
while($ri = mysql_fetch_array($res))
{
echo "<option value=" .$ri['name'] . ">" . $ri['name'] . "</option>";
}
?>
如果这就是我理解你想要的你所说的带值字段是什么意思?你想让select Box/10021和John的值和文本都在textbox中结算吗?你几乎知道我的意思,当我从comboBox中选择“Alex”时,textfield直接显示“10027”,因为该字段与表类似。你试过下面的ans吗?看到mysql_*函数仍在使用,我的心都在流血。cardtype是什么?抱歉,在我更改代码之前,我从未尝试过JQuery。。您必须为select和textbox提供ID属性。它可以工作!非常感谢。我还有一个问题,我只是尝试另一种可能性…当我将Alex的“class”字段从“10027”更改为“ABCD EFG”,然后从组合框中选择它时,文本字段只显示第一个单词(“ABCD”)。怎么可能呢?
<?
while($ri = mysql_fetch_array($res))
{
echo "<option value=" .$ri['name'] . ">" . $ri['name'] . "</option>";
}
?>
<?
while($ri = mysql_fetch_array($res))
{
echo "<option value=" .$ri['class'] . ">" . $ri['name'] . "</option>";
}
?>