dongzhuandian3292 2015-07-04 15:38
浏览 37
已采纳

更改JQuery的问题选择Bracket值

On my site, the user selects a person, and when the selection is made, it populates demographics about that patient below, but gives the user the options to change each demographic value. I have an html select statement for a "Prep RN" that is populated from a table of RNs when the form is loaded, but when I select a patient, I can't get it to change the select to the RN that is stored in the database and is contained in the list:

$.ajax({
    url: 'php/pullselectedpatient.php',
    type: 'POST',
    dataType: 'json',
    cache: false,
    data: {Patient_UID: tempPatient_UID},
    success: function(data) {
        if (data.Prep_RN == 'Unassigned') {
            //if unassigned, set option to unassigned
            $('#selectpreprn').val('Unassigned');
        } else {
            //if assigned, change to selected RN
            $('#selectpreprn').val(data.Prep_RN);
    },
    error: function() {
        alert("ajax call failed.");
    }
});

This code fills the option list successfully, but in case it's part of the problem, here it is:

<label for='selectpreprn'>Prep RN: </label>
<select id="selectpreprn">
    <option value="empty"></option>
    <?php
        require('php/pullrns.php');
        //loop and add the patients to the drop down list
        foreach($result_rns->fetch_all(MYSQLI_ASSOC) as $row) {
            echo "<option value='", $row['RN_UID'], "'>", $row['RN_UID'], "</option>";
        }
    ?>
</select>

This results with the select filled with a 'blank', 'Unassigned', and then 3 names to choose from.

Also, this is my first time posting to this site (which is amazingly helpful), so I hope I provided everything. I have spent at least 3 hours trying different things to make this work.

To reiterate, the problem is that it doesn't select the option in the select tag when the patient is selected. It just stays blank.

  • 写回答

1条回答 默认 最新

  • dongmi5607 2015-07-04 15:55
    关注

    This code works as intended, the issue was further down my page where I was inadvertently overwriting this selector. I copied and pasted similar code, and it got me in trouble =(

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效