douchi8503 2016-09-23 14:53
浏览 132
已采纳

JQuery AJAX - 填充文本框和下拉框

This is my first time using JQuery AJAX so I’m not very familiar with the syntax. Right now I’m pulling a set of values from a database and populating a dropdown box. What I need AJAX to do is populate three other fields with hardcoded information when they make a selection from the dropdown box. Once I get AJAX working correctly, I’d then like to query the database and return results based on their selection from the dropdown.

<div class="panel-body">
    <div class="form-group">
        <label for="nomName" class="col-sm-3 control-label">Name:</label> 
        <div class="col-sm-8">              
            <input type="text" class="form-control" data-validation="required" name="nomName" id="nomName" placeholder="Name" maxlength="50">           
        </div>
    </div>
    <div class="form-group">
        <label for="nomTitle" class="col-sm-3 control-label">Title:</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" data-validation="required" name="nomTitle" id="nomTitle" placeholder="Title" maxlength="50">
        </div>
    </div>
    <div class="form-group">
        <label for="nomDept" class="col-sm-3 control-label">Department:</label>
        <div class="col-sm-8">
            <select class="form-control" name="nomDept" id="nomDept">
                <option value="" disabled selected>Select a Department...</option>
                <option value="Building Services">Building Services</option>
                <option value="Construction Management">Construction Management</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="nomGUID" class="col-sm-3 control-label">AU Email/GUID:</label>
        <div class="col-sm-8">
            <select class="form-control" name="nomGUID" id="nomGUID">
                <option value="" disabled selected>Select a Person...</option>
                <?php
                while($row = mssql_fetch_array($user_list)){
                    echo "<option value=\"" . $row['id'] . "\">" . $row['id'] . "</option>";
                }
                ?> 
            </select>
        </div>
    </div>
</div>

And here is my AJAX. I know it's not correct, so I'd appreciate some explanation behind someone's solution if they provide one. Thanks.

$(function() {
    var options = {
        "Option 1": "value 1",
        "Option 2": "value 2",
        "Option 3": "value 3"
    }
    $('#nomGUID').change(function() {
        $.ajax({
            url: 'test.php',
            success: function('#options') {
                $('#nomDept').empty();
                $('#nomTitle').html('Test AJAX');
            }
        })
    }
}
  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 关于学生成绩的一个系统(语言-c语言)
      • ¥60 matlab传染病模型分段
      • ¥15 关于#matlab#的问题,如何解决?
      • ¥15 51单片机汇编语言Keil5基础问题!
      • ¥15 CygwinPortable 中 NumPy 无法安装
      • ¥15 vivado如何支持多维打包数组模式
      • ¥15 请问第13题到底应该怎么做
      • ¥15 stable diffusion报错问题
      • ¥20 数据可视化综合运用 导入npz文件以及读取内容
      • ¥15 倒计时汇编语言RTC实时时钟