combox不工作plz检查它.. [英] combox not working plz check it ..

查看:56
本文介绍了combox不工作plz检查它..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 employess.php 

<? 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 >
< / head >
< ; 正文 >
< div id = content >
< h1 align = center > 添加培训< / h1 >
< 表格 action = employess.php 方法 = < span class =code-keyword> post >
< div >
& p >
培训ID:
< input 类型 = text 名称 = Training_ID >
< / p >
< p >
员工ID:
< 选择 id = JOB_NO >
< 选项 = > 选择一个< / option >
<? php

$ st = $ pdo - > prepare(SELECT JOB_NO FROM mm_client_loc_job);
$ st-> execute();
$ rows = $ st-> fetchAll(PDO :: FETCH_ASSOC);
foreach(行数为$行){
?> < 选项 value = <?php echo $ row ['JOB_NO'];?> > <? php echo $ row ['JOB_NO']; > < / option > <? php

}

>
< ; / select >
< p >
名字:
< span class =code-keyword><
input type = text 名称 = CLIENT_NAME id = CLIENT_NAME >
< / p >
< p >
姓氏:
< 输入 < span class =code-attribute> type = text 名称 = LOC_NAME id = LOC_NAME >
< / p >
< p >
需要培训吗?
< 选择 < span class =code-attribute> name
= 培训 >
< 选项 value = > 选择... < / option >
< 选项 value = 客户服务 > 客户服务ice < / option >
< 选项 value = Bailer > Bailer < / option >
< 选项 value = 接待 > 接收< /选项 >
< 选项 value = Fish&肉类柜台 > 鱼类和肉类柜台< / option >
< 选项 value = 奶酪计数器 > 奶酪计数器< / option >
< / select >
< / p >
< 输入 type = submit >
< /表格 >
< / div >
< script type = text / javascript >
$(function(){//当DOM准备好时,将执行此代码
$('#JOB_NO')。change(function(){//当Employee_ID元素的值发生更改时,将触发
var $ self = $(本);
alert(JOB_NO); //我们创建一个jQuery对象,其中select为
$ .post(getEmployeeData.php,{JOB_NO:$ self.val()},function(json)
{
if (json&& json.status){
$('#CLIENT_NAME')。val(json.name);
$('#LOC_NAME')。val(json.lastname);
}
})
});
})
< / script >
< / body >
< / html >

getEmployeeData.php

<? php

< span class =code-summarycomment> $ pdo
= new PDO(mysql:host = localhost; dbname = erp1314; charset = utf8 < span class =code-summarycomment> root, );

< span class =code-summarycomment>

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



// 作为 可以 参见, 此处 其中 Employee_ID = :employee_id,

// 自动 已取代 by PDO object with 数据 已发送 execute(array('employee_id' = > $ _POST ['Employee_ID']))
//这是避免SqlInyection攻击的好习惯

$ st = $ pdo- >准备(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']));
$ 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 类型 = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js > < / script >
< / head >
< body >
< div < span class =code-attribute> id = content >
< h1 align = < span class =code-keyword> center > 添加培训< < span class =code-leadattribute> / h1 >
< 表格 action = employess.php 方法 = 发布 >
< div >
< p >
培训ID:
< inp ut type = text name = Training_ID >
< / p >
< span class =code-keyword>< p >
员工ID:
< 选择 id = JOB_NO < span class =code-keyword>>
< 选项 value = > 选择一个< / option >
<? php


st =


pdo - > prepare(SELECT JOB_NO FROM mm_client_loc_job);

employess.php

<?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>
</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);
alert(JOB_NO); // We create an jQuery object with the select inside
 $.post("getEmployeeData.php", { JOB_NO : $self.val()}, function(json)
 {
 if (json && json.status) {
$('#CLIENT_NAME').val(json.name);
 $('#LOC_NAME').val(json.lastname);
 }
 })
            });
        })
    </script>
    </body>
</html>

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 SqlInyection 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']));
$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="stylesheet" href="style.css"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> </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");


这篇关于combox不工作plz检查它..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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