我有这个令人敬畏的代码片段,我试图将其放入数据填充的形式,但我仍然试图让它工作,我可以看到函数本身正在工作,但我仍然有一些错误,我只是无法解决问题。当我确实得到它的功能时,它回应了内部代码,我似乎无法填充sql中的数据。它看起来大部分都不错,但我确定只有一件事情不存在。
任何人都可以看到可能出错的地方吗?
<?
include 'conn.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery-1.12.3.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$.get( "myfunctions/get_records_for_select.php", function( data ) {
//Look we will change the HTML content for our select-box on success
$( "#myselectbox" ).html( data );
});
$( "#myselectbox" ).change(function() {
$.post( "myfunctions/get_records_by_id.php", { selectedId: $(this).val() })
.done(function( data ) {
$( "#myinputbox" ).val( data );
});
});
});
</script>
</head>
<body>
<select id="myselectbox">
<option>Select</option>
</select>
<input type="text" id="myinputbox">
</body>
</html>
<?
// your get_records_for_select.php file
include '../conn.php';
$yourSql = "SELECT * FROM `intrusion`";
$results = run_sql($yourSql);
$html = "<option></option>";
foreach($results as $record){
$html .= "<option value=" . $record['SAPCode'] . "></option>";
}
echo $html;exit;
?>
<?
include '.../conn.php';
// your get_records_by_id.php file
$post_data = $_POST['SAPCode'];
$yourSql = "select * FROM intrusion WHERE id=".$post_data;
$results = run_sql($yourSql);
$row = $results->row();
echo $row['SAPCode'];exit;
?>
//更新了index.php表单,其中sql已填充数据正在运行,但仍然没有更改功能ID
&#34 ;;
echo&#34;&#34 ;;
while($ row = mysql_fetch_array($ q))
{
echo&#34;&#34;。$ row [&#39; SAPCode&#39;]。&#34;&#34 ;;
}
echo&#34;&#34 ;;
?&GT;
答案 0 :(得分:0)
尝试写 -
`<select id="myselectbox" onchange="FunctionName()">
<option>Select</option>
</select>
function FunctionName(){
$.post( "myfunctions/get_records_by_id.php", { selectedId: $(this).val() })
.done(function( data ) {
$( "#myinputbox" ).val( data );
});
}`
您正在添加更改事件onready但是从ajax加载数据,因此它没有获得select的当前内容。