大家好,任何人都可以帮助我,我已经解决了我的问题,但我无法将值从div传递到输入字段,需要请 page1.php中
<!doctype html>
<?php
$conn = mysql_connect('localhost','root','') or die (mysql_error);
$db = mysql_select_db('employee', $conn) or die (mysql_error);
$select = "SELECT * FROM employee ";
$result = mysql_query($select);
$option = '';
while($row = mysql_fetch_assoc($result)){
$option .= '<option value="'.$row['id'].'">'.$row['employee_name'].'</option>';
}
?>
<html>
<head>
<title>Retrieve data from database using Ajax</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function getData(q, a){
$.ajax({
url: 'loademployeedata.php?empid='+q, //call storeemdata.php to store form data
success: function(html) {
var ajaxDisplay = document.getElementById(a);
ajaxDisplay.innerHTML = html;
}
});
}
$(document).ready(function(){
$("#tyt").live("change", function() {
$("#ab ").val($(this).find("option:selected").attr("value"));
});
});
</script>
</head>
<body>
<form method="post">
<select id="tyt" onchange="getData(this.value, 'dis')" >
<?php
echo $option;
?>
</select>
<div id="dis" >
</div><input name="" type="text" id="ab" >
</form>
</body>
第二个连接页面是
<?php
$empid = $_GET['empid'];
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server..
$db = mysql_select_db("employee", $connection); // Selecting Database
if (isset($empid)) {
$query = " SELECT * FROM employee WHERE id = '$empid'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$a=$row['employee_salary'];?>
<?php echo $a; ?>
<?php }
}
mysql_close($connection); // Connection Closed
?>
我只需要将值而不是div均值放入输入字段
答案 0 :(得分:0)
尝试这样的事情(未经测试):
{{1}}