combox选择值,但文本框不填写选择plz chek它在哪里错误... [英] combox select value but textbox not fill against selection plz chek it where mistake ...

查看:92
本文介绍了combox选择值,但文本框不填写选择plz chek它在哪里错误...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

employess.php

employess.php

<?php
// First of all, don't make use of mysql_* functions, those are old
$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <!-- You will need jQuery (or anyother javascript framework) to accomplish your goal cause you need ajax -->
        <title>Training</title>
    </head>
    <body>
        <div id="content">
           <h1 align="center">Add Training</h1>
<form action="employess.php" method="post">
                <div>
                    <p>
                        Training ID:
                        <input type="text" name="Training_ID">
                    </p>
                    <p>
                        Employee ID:
                        <select id="JOB_NO" >
                            <option value="">Select one</option>
                            <?php
                            $st = $pdo->prepare("SELECT JOB_NO FROM mm_client_loc_job");
                            $st->execute();
                            $rows = $st->fetchAll(PDO::FETCH_ASSOC);
                            foreach ($rows as $row) {
                                ?><option value="<?php echo $row ['JOB_NO']; ?>"><?php echo $row ['JOB_NO']; ?></option><?php
                            }
                        ?>
                        </select>
                    <p>
                        First name:
                        <input type="text" name="CLIENT_NAME" id="CLIENT_NAME">
                    </p>
                    <p>
                        Last name:
                        <input type="text" name="LOC_NAME" id="LOC_NAME">
                    </p>
                    <p>
                        Training required?
                        <select name="Training">
                            <option value="">Select...</option>
                            <option value="Customer Service">Customer Service</option>
                            <option value="Bailer">Bailer</option>
                            <option value="Reception">Reception</option>
                            <option value="Fish & meat counters">Fish & meat counters</option>
                            <option value="Cheese counters">Cheese counters</option>
                        </select>
                    </p>
                    <input type="submit">
            </form>
        </div>
    <script type="text/javascript">
        $(function() { // This code will be executed when DOM is ready
            $('#JOB_NO').change(function() { // When the value for the Employee_ID element change, this will be triggered
                var $self = $(this);
             // We create an jQuery object with the select inside

                $.post("getEmployeeData.php", { JOB_NO : $self.val()}, function(json)
                   {
                     alert($self.val());
                    if (json && json.status) {
                        $('#CLIENT_NAME').val(json.name);
                        $('#LOC_NAME').val(json.lastname);


                    }
                })
            });
        })
    </script>

    </body>
</html>



getEmployeeData。 php


getEmployeeData.php

<?php
$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");

//
header("Content-Type:application/json; Charset=utf-8");

// As you can see, here you will have where Employee_ID = :employee_id, this will be
// automatically replaced by the PDO object with the data sent in execute(array('employee_id' => 
$_POST['Employee_ID']))
// This is a good practice to avoid Sql Injection attacks

$st = $pdo->prepare("SELECT CLIENT_NAME, LOC_NAME FROM mm_client_loc_job WHERE JOB_NO = :job_No LIMIT 1");
$st->execute(array (':job_No' => $_POST['Job_No']));
echo (job_no);
$data = $st->fetch(PDO::FETCH_ASSOC);
echo json_encode(array ('status' => true, 'name' => $data ['CLIENT_NAME'], 'lastname' => $data ['LOC_NAME']));
?>

推荐答案

pdo = new PDO( mysql:host = localhost; dbname = erp1314; charset = utf8 root );
?>
< html >
< head >
< link type = text / css rel = 样式表 href = style.css / >
< script type = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js > < / script > <! - 您将需要jQuery(或任何其他javascript框架)来实现您的目标,因为您需要ajax - >
< title > 培训< / title >
< / head >
< body >
< div id = content >
< h1 align = center > 添加培训< / h1 >
< 表格 action = employess.php 方法 = 发布 > ;
< div >
< p >
培训ID:
< 输入 < span class =code-attribute> type = text 名称 = Training_ID >
< / p >
< p >
员工ID:
< 选择 id = JOB_NO >
< 选项 = > 选择一个< / option >
<? php
pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", ""); ?> <html> <head> <link type="text/css" rel="stylesheet" href="style.css"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <!-- You will need jQuery (or anyother javascript framework) to accomplish your goal cause you need ajax --> <title>Training</title> </head> <body> <div id="content"> <h1 align="center">Add Training</h1> <form action="employess.php" method="post"> <div> <p> Training ID: <input type="text" name="Training_ID"> </p> <p> Employee ID: <select id="JOB_NO" > <option value="">Select one</option> <?php


st =
st =


pdo-> prepare( SELECT JOB_NO FROM mm_client_loc_job);
pdo->prepare("SELECT JOB_NO FROM mm_client_loc_job");


这篇关于combox选择值,但文本框不填写选择plz chek它在哪里错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆