Like the title says, I'm trying to update select boxes. But it isn't working for me.
My HTML:
<div class="col-sm-3">
<select class="form-control" id="answer9">
<option value="00">Select</option>
<option value="0">0 - No Problems</option>
<option value="1">1 - Some Problems</option>
<option value="2">2 - Considerable Problems</option>
<option value="3">3 - Severe Problems</option>
</select>
</div>
JQuery & AJAX:
$('#fetch').click(function(){
var nameid = parseInt($('#names').val());
if(nameid == 0){
$('#showerr').html("Please Select an Client").show().delay(3000).fadeOut("slow");
$('#names').focus();
return false;
}
$.ajax({
url : 'wsevaluationresult.php',
type : "POST",
datatype : "JSON",
data : {
'editvalues' : 1,
'id' : nameid
},
success:function(re){
$('#answer9').val(show.answ9);
}
});
});
PHP & MySQL:
if(isset($_POST['editvalues'])) {
$stmt = $db->prepare('SELECT clientid, answ9
FROM evals
WHERE a.memberid = :memberid
AND clientid = :id');
$stmt->bindValue(':memberid', $_SESSION["memberid"], PDO::PARAM_INT);
$stmt->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row) {
header("Content-type: text/x-json");
echo json_encode($row);
}
exit();
}
I've found a few suggestions here on SO, but none really address this. All I'm wanting is for the select box to reflect the value from the db for answ9. The way I'm doing the ajax
works for me when I'm using text boxes. But the select boxes are a whole other game. Any help is appreciated. Thanks.