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

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 template模板的参数问题
      • ¥50 搭建青柚H5过程中出现的问题
      • ¥15 查找处理学生信息问题,含多个文件,显示问题是无法调用其中一个文件
      • ¥15 simulink生成代码后提示告警
      • ¥16 jieba提取高频词,生成文件是空的
      • ¥15 怎么读取服务器中的文件去配置mongo的连接
      • ¥20 Python如何统计文本中两字及以上的词语个数
      • ¥15 MapReduce自定义对象怎么写
      • ¥15 看下哪里错了,程序应该没错
      • ¥15 前端连接eventbus时,检查定位到send出现问题,对前端毫无头绪