Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过AJAX、PHP和MYSQL从下拉列表中更改文本框_Php_Javascript_Mysql_Ajax - Fatal编程技术网

通过AJAX、PHP和MYSQL从下拉列表中更改文本框

通过AJAX、PHP和MYSQL从下拉列表中更改文本框,php,javascript,mysql,ajax,Php,Javascript,Mysql,Ajax,我有一个由两列组成的表,ContactName和Usertype。我有一个下拉列表,其中包括ContactName中的数据。当我在下拉列表中选择任何值时,其用户类型应该根据所选内容显示。请帮帮我。到目前为止,我已经做了很多。当我在下拉列表中选择任何值时,将显示相同的值,但我需要用户类型 <?php if(!isset($_SESSION)) { session_start(); } $dingo=$_SESSION['dingo']; $

我有一个由两列组成的表,ContactName和Usertype。我有一个下拉列表,其中包括ContactName中的数据。当我在下拉列表中选择任何值时,其用户类型应该根据所选内容显示。请帮帮我。到目前为止,我已经做了很多。当我在下拉列表中选择任何值时,将显示相同的值,但我需要用户类型

<?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);
?>

<form method="post" action="">

<?php
    $SQLString="SELECT distinct(G1_OPPID),ContactName from rahul_tbl_opportunities where G1_OPPID IS NOT NULL and ContactName!='' ";
    $result1 = mysql_query($SQLString); 
    $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>

我收集的信息是,您只想让文本框显示当前在选择框中选择的内容

将选择框中的onchange事件更改为:

onchange="transferValue();"
并添加此脚本标记:

<script type="text/javascript">
    function transferValue(){
        var selectBox = document.getElementById("select1");
        var selectedOption = selectBox.options[selectBox.selectedIndex].value;
        var textBox = document.getElementById("test");
        textBox.value = selectedOption;
    }

    window.onload = function(){
        transferValue();
    };
</script>

函数transferValue(){
var selectBox=document.getElementById(“select1”);
var selectedOption=selectBox.options[selectBox.selectedIndex].value;
var textBox=document.getElementById(“测试”);
textBox.value=selectedOption;
}
window.onload=函数(){
transferValue();
};

你有什么不顺眼的地方吗?你试过的javascript在哪里?@karthikr他写的唯一一个javascript是标记你必须包含一些javascript/jquery,比如:实现你想要的东西。将ID更改为您在实现中使用的ID很抱歉,这是我的javascript代码函数load_value(value){document.getElementById(“test”).value=value;}不,实际上我的文本框值与选择框不同。