Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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
Javascript 使用所选数据搜索mysql表并设置输入字段的值_Javascript_Php_Html_Jquery Chosen - Fatal编程技术网

Javascript 使用所选数据搜索mysql表并设置输入字段的值

Javascript 使用所选数据搜索mysql表并设置输入字段的值,javascript,php,html,jquery-chosen,Javascript,Php,Html,Jquery Chosen,我很难在jquery中使用change事件来搜索mysql表,并使用在表单的输入字段中找到的列作为默认列。我最初将注册号作为选项存储在选择下拉列表中。代码如下: //store reg_1 options $get_1=mysql_query("SELECT reg, reg_date FROM vehicle_reg"); $option_reg = '<option value = ""></option>'; while($row = mysql_fet

我很难在jquery中使用change事件来搜索mysql表,并使用在表单的输入字段中找到的列作为默认列。我最初将注册号作为选项存储在选择下拉列表中。代码如下:

    //store reg_1 options
 $get_1=mysql_query("SELECT reg, reg_date FROM vehicle_reg");
$option_reg = '<option value = ""></option>';
 while($row = mysql_fetch_assoc($get_1))
{

  $option_reg .= '<option value = "'.$row['reg'].'">'.$row['reg'].'</option>';
}
mysql搜索的php代码:

<?php

include_once('connection.php');

if(isset($_GET['s']) && $_GET['s'] != ''){
    $s = $_GET['s'];
    $sql = "SELECT * FROM `vehicle_reg` WHERE reg LIKE '%$s%'";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        $reg = $row['reg'];
        $reg_date = $row['reg_date'];
        $_SESSION['reg_date'] = $reg_date;
    }

} ?>
把它放到注册表日期输入栏似乎没有发生,我想知道是否有人能发现这个问题

          $(document).on('change', '#reg_1', function () {
        if ($("#reg_1 option:selected").val() !== "") {
            var reg = $("#reg_1 option:selected").val();
            search(reg);
            alert("well done!");
        } else {
            alert("select non-blank registration!");

        }
      });           

    function search(string){
        var xmlhttp;
        if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
        }else{
            xmlhttp = new ActiveXObject("XMLHTTP");
        }
        xmlhttp.onreadystatechange = function(){
            if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
                document.getElementById("temp").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "search_vehicle_reg.php?s="+string, true);
        xmlhttp.send(null);

        jQuery(document).ready(function ($) {
                var regDate = '@Request.RequestContext.HttpContext.Session["reg_date"]';
                document.getElementById("reg_date_1").value = $regDate;
            });             
<?php

include_once('connection.php');

if(isset($_GET['s']) && $_GET['s'] != ''){
    $s = $_GET['s'];
    $sql = "SELECT * FROM `vehicle_reg` WHERE reg LIKE '%$s%'";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        $reg = $row['reg'];
        $reg_date = $row['reg_date'];
        $_SESSION['reg_date'] = $reg_date;
    }

} ?>
            jQuery(document).ready(function ($) {
                var regDate = '@Request.RequestContext.HttpContext.Session["reg_date"]';
                document.getElementById("reg_date_1").value = $regDate;
            });