0

我有从 mysql 填充的 texbox 和下拉列表。我想使用下拉列表更改文本框值。我的文本框值也从 mysql 填充。这是我的代码。提前致谢。

<?php
if(!isset($_SESSION)){
    session_start();
}

$dingo=$_SESSION['dingo'];
$query11="Select ISO3,Notify,Dingoid from rahul_tbl_users where Dingoid=$dingo";
$query123=mysql_query($query11);
$query1234=mysql_fetch_array($query123);
$fetch=mysql_query(" SELECT tdd.Dingoid,
                            tc.Dingoid,
                            tc.A_End,
                            tbidd.OpportunityNumber,
                            tbidd.Status,
                            tbidd.Country,
                            tbidd.OpportunityName,
                            tbidd.Allocatedto,
                            tbidd.Email,
                            tbidd.Customer,
                            tbidd.Country,
                            tbidd.ContactName,
                            tc.Usertype,
                            tbidd.G1_OPPID
                        FROM  scott123.rahul_tbl_users tdd 
                            INNER JOIN scott123.rahul_user_opps tc 
                                ON tdd.Dingoid=tc.Dingoid 
                            INNER JOIN scott123.rahul_tbl_opportunities tbidd
                                ON tc.A_End=tbidd.OpportunityNumber
                        WHERE tc.Dingoid =$dingo"
                         );
$fetch_result=mysql_fetch_array($fetch);
?>

<?php
$SQLString="SELECT distinct(G1_OPPID),ContactName from rahul_tbl_opportunities
                WHERE G1_OPPID IS NOT NULL and ContactName!='' ";
$result1 = mysql_query($SQLString);
?>

<form id="form1" method="post" action=""> <br>
 <table class="gridtable">
   <tr>
        <th>
            <strong>Users Permission </strong></th></tr>
            <br>
            <tr>
            <td>
                <?php
                    //filename: populate.php
                    if (!empty($_POST)) {
                        switch ($_POST['select1']) {
                            case 1: 
                                $value = $rows1['ContactName'];
                                break;
                            default:
                                $value = '';
                        }
                    }
                ?>
                <select name="select1"  onchange="onchange="this.form.submit();">
                <?php
                    while($rows1=mysql_fetch_array($result1)){
                ?>
                    <option id='user_name' value="<? echo $rows1['ContactName']; ?>"><? echo $rows1['ContactName']; ?></option>
                <?php
                    }
                ?>
                    <input type="text" name="test" value="<?php echo $value;?>" />
                </select>

                <input type="submit" name="submit_name11" value="Add Permission"/>
                <input type="submit" name="submit_name12" value="Edit Permission"/>
            </td>
        </tr>
   </table>
</form>
4

1 回答 1

0

你在选择框中使用了两次onchange事件我修改了你可以尝试的代码,如果你想以看起来的方式输出。你不需要php将值放在你可以使用的文本框中javascript。 .

    <script type="text/javascript">
      function load_value(value)
     {
         document.getElementById("test").value=value;
     }
     </script>
      <form method="post" action="">  
            <?php
            $select_box='<select name="select1"  id="select1" onchange="javascript:load_value(this.value);">';
            $input="";
            while($rows1=mysql_fetch_array($result1)){

            $select_box .='<option id="user_name"  value="'.$rows1["ContactName"].'">'.$rows1['ContactName'].'</option>';

            }
        $input ='<input type="text" name="test" id="test" value="" />';

    echo $select_box."</select>";
    echo $input;
        ?>

<input type="submit" name="submit_name11" value="Add Permission"/>
<input type="submit" name="submit_name12" value="Edit Permission"/>

    </form>
于 2013-05-25T10:26:43.010 回答