Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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
Php 我想将选定的选项从一个文本框传递到另一个文本框_Php_Mysql_Json_Mysqli - Fatal编程技术网

Php 我想将选定的选项从一个文本框传递到另一个文本框

Php 我想将选定的选项从一个文本框传递到另一个文本框,php,mysql,json,mysqli,Php,Mysql,Json,Mysqli,当用户键入并选择其中一个选项时,第一个框将自动完成。该值来自具有3个属性的数据库:id、name和value。我希望第一个文本框中所选名称的值自动显示在第二个框中。一旦用户选择了名称,如何携带名称的值 index.php: <script type="text/javascript"> $(document).ready(function() { $('#auto').autocomplete( { source

当用户键入并选择其中一个选项时,第一个框将自动完成。该值来自具有3个属性的数据库:id、name和value。我希望第一个文本框中所选名称的值自动显示在第二个框中。一旦用户选择了名称,如何携带名称的值

index.php:

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#auto').autocomplete(
        {
            source: "search.php?json",
            minLength: 3

        });
    });


</script>

 </head>

   <body>
    <p>Type the name of a band: <input type="text" id="auto" /></p>


   </body>
     </html>

       search php file 

             <?php
         $mysqli = taken off;
       $text = $mysqli->real_escape_string($_GET['term']);

              $query = "SELECT name, salary FROM tag WHERE name LIKE '%$text%' ORDER BY     
                name ASC";
             $result = $mysqli->query($query);
            $json = '[';
               $first = true;
                 while($row = $result->fetch_assoc())
                           {
                       if (!$first) { $json .=  ','; } else { $first = false; }
                   $json .= '{"value":"'.$row['name'].'"}';

                      }
                       $json .= ']';

                echo $json;

                     ?>

尝试在自动完成中添加触发器,方法如下

$( '#auto' ).autocomplete({
    select: function( event, ui ) {
        var myValue = $(this).val();
        //Do what you want with your value
    }
});
这起作用了

  <script type="text/javascript">
    $(document).ready(function()
    {
        $('#auto').autocomplete(
        {
            source: "search.php?json",
            minLength: 3,
            close: function( event, ui ) { getSalary(document.getElementById('auto').value) },
            change: function( event, ui ) { getSalary(document.getElementById('auto').value) },
            select: function( event, ui ) { getSalary(document.getElementById('auto').value) }

        });
    });

    function getSalary(name_salary){
        $.post( "salary.php", { term: name_salary }, function(data) {                                           
                var test = JSON.parse(data);
                document.getElementById('autosalary').value = test.value;
                $( "#mincome" ).text(test.value); 

                     });    

        }       
     </script>