1
+---------+------------+
| class   | name       | 
+---------+------------+
| 10021   | John       | 
| 10027   | Alex       |  
| 10030   | Brian      |  
| 10033   | Anita      |
+---------+------------+

textfieldコンボボックスからメニューの1つを選択すると、同期しようとしています。

<?
$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>";
?>

たとえばAlex、コンボボックスから選択するtextfieldと、フィールドに値が表示されます10027

4

2 に答える 2

2

whileループにあるものを変更value=" .$ri['name'] to value=" .$ri['class']し、選択ボックスの変更時に使用して、JQueryでテキストボックスの値を変更します...

1)JQuery

$('#idofselectbox').change(function() {
        $('#idoftextbox').val($('#cardtype :selected').val());
          /*OR    $('#idoftextbox').val($(this).val());  */
});

また

echo "<input disabled type='text' value=".$ri['class'].">". $ri['class'] . "</input>";
to
echo "<input disabled type='text' value='' >";

テキストボックスの値を動的に設定しているためです。

2)Javascript:

<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'>

デモ: http: //jsfiddle.net/bhavinrana07/yjWmt/

于 2012-12-29T05:53:03.497 に答える
1

それ以外の

<?
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>";
}
?>

それなら私はあなたが欲しいものを理解しています

于 2012-12-29T08:36:24.333 に答える