如何将指定的值放到下拉列表中已循环的每个文本框中?
下面是我的PHP代码:
<?php
while($rowb=mysql_fetch_array($b1))
{
?>
<input type="text" id="friendName">
<select name="select[]" id="select" onchange="ChooseContact(this)"/>
<?php
while($qrow=mysql_fetch_array($q1))
{
<option value="<?php echo $qrow['type'];?>"><?php echo $qrow['type'];?></option>
<?php
}
}
?>Javascript:
function ChooseContact(data) {
document.getElementById ("friendName").value = data.value;
}好的,为了让代码更清晰,我已经对代码进行了编辑,为第一个代码道歉。
这个例子的输出是,假设我调用它来循环2次。下拉菜单的选项值为"a“和"b”。所以他们将是2个下拉菜单和2个输入框。当我从第一个下拉列表中选择一个值时,假设是"a“,那么第一个输入框值也是"a”。但是当我在第二个下拉菜单中选择“让我们说"b”时,第二个输入框的值应该是"b“,但它显示为空白,并且第一个输入框的值"a”变成了"b“。我希望"b“应该出现在第二个输入框,但我不知道如何做到这一点。
请帮帮TNX!!
发布于 2013-03-10 14:50:52
试试这个:
<?php
while($rowb=mysql_fetch_array($b1))
{
?>
<input type="text" id="friendName">
<select name="select[]" id="select" onchange="ChooseContact(this)" >
<?php
while($qrow=mysql_fetch_array($q1))
{
?>
<option value="<?php echo $qrow['type']; ?>"><?php echo $qrow['type']; ?></option}
<?php
}
?>
</select>
<?php
}
?>发布于 2013-03-10 14:56:16
while($rowb=mysql_fetch_array($b1))
{
?>
<input type="text" id="friendName">
<select name="select[]" id="select" onchange="ChooseContact(this)">
<?
while($qrow=mysql_fetch_array($q1))
{
?>
<option value="<?echo $qrow['type'];?>"><? echo $qrow['type'] ?> </option>
<?
}
}编辑:
我认为应该将<input type="text" id="friendName">改为<input type="text" name="friendName[]">,然后将function改为如下所示
function ChooseContact(data)
{
var x = document.getElementsByName("friendName[]");
for (i=1; i < x.length; i++) {
x[i].value = data.value ;
}
}https://stackoverflow.com/questions/15319664
复制相似问题