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.