Setting Value for <Select> object
Hello:
I'm trying to populate a <Select> object with the value from a user's record. Following is my current attempt:
- var var_ClientType = <? echo json_encode($ClientType)?>;
- $(document).ready(function() {
- //===================== POPULATE Drop down List =================
- $.getJSON('select_orgtype.php', function(data) {
- var select = $('#orgType');
- console.log("Var ClientType: " + var_ClientType);
- $("#orgType option:text=" + var_ClientType +"").attr("selected", "selected");
- $.each(data, function(i, value) {
- $('#orgType').append($('<option>').text(value.ClientType).attr('value', value["0"]));
- });
- // $("#orgType").val(var_POST['orgType']); // This line will repopulate field if there are posting errors
- });
- }); // END Document Ready Function
Something is wrong. The list within $.each(data, function(i,value) constructs just fine.
But, the <option> is not populating with var_ClientType.
var_ClientType displays in the console.log, so I know the variable is picking up the value. For some reason, my script is not assigning this value to the orgType <option>.
Any assistance is greatly appreciated.
Thanks Much:
Pavilion