Jquery下拉菜单和输入表单功能不太正常

Jquery drop down and input form function not quite working

本文关键字:功能 表单 下拉菜单 输入 Jquery      更新时间:2023-09-26

我有一段很棒的代码,我正试图将其放入数据填充的表单中,但我仍在努力使其工作,我可以看到函数本身正在工作,但仍有一些问题我无法解决。当我让它发挥作用时,它正在回显内部代码,我似乎也无法从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";echo";while($row=mysql_fetch_array($q)){
echo"$行["SAP代码"]。";}echo";?>

尝试写入-

`<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的当前内容。