php - 使用下拉菜单更改 mysql 文本框值 PHP,mysql

标签 php mysql ajax textbox html-select

我有从 mysql 填充的文本框和下拉列表。我想使用下拉列表更改文本框值。我的文本框值也从 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>

最佳答案

您在选择框中使用了两次 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>

关于php - 使用下拉菜单更改 mysql 文本框值 PHP,mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16748548/

相关文章:

php - { } 在字符串中做什么?

php - 获取 YouTube 最高缩略图分辨率

javascript - 我的 jquery 函数中的 every 出现错误

php - mysql中如何插入多个字段

php - Symfony2:间歇性高响应时间/慢 SessionHandlerProxy::read() 完成

php - MYSQL:仅选择最新记录(在左侧连接表上)

MySQL 自定义引擎 : already existing data

mysql - Wordpress SQL 查询以获取自定义帖子类型中的 meta_key 名称

jquery - ajax如何从golang代码中获取数据?

php - html中的ajax,从php中获取结果