So thanks to some great feedback from my previous question, I have moved further: Original Post - Coldfusion Populate form with dropdown selection using ajax
So now, I have successfully submitted a request to my CFC and it has a remote function but I'm not getting anything returned to the browser.
The code looks like this:
<script>
function loadQuery() {
var assign = $("#existingAssignment").val(); // Get the value of the select box so we can build the next page
$.ajax({
type: 'get',
url: 'http://127.0.0.1/WMT/model/getCandidate.cfc',
data: {method:'getExistingAssignPosInfo', tourid : assign},
dataType: 'json',
async: false,
success: function(result){
var myDP4 = $('#dp4').val(result.STROTG);
$('#dp4').val(result.STROTG);
$('#dp5').val(result.STRDEPART);
}
});
}
</script>
I am trying to have jQuery replace the results (which are coming back. I can see them in Firebug) into a form field. The fields are named dp4
and dp5
etc. I have tried setting a result to myDP4
and setting that value and it doesn't work.
I have also tried throwing an alert to the screen and that doesn't work as I assume it would put the alert on the ajax call.
The only other thing to do after filling in the form values would be to set two dropdowns on the screen to equal the number that is being passed back.
For example:
<option value="1">Name1</option>
<option value="2">Name2</option>
<option value="3">Name3</option>
<option value="4">Name4</option>
If my ajax returns 3 for the name of the select with the options, how would I send that info to jQuery so that it selects that in the drop down?
TIA!
UPDATE: one of the things that I added to my CFC was returnformat="JSON"
that was not there before and I do see a JSON object when I call the CFC directly. However, there are no leading slashes as suggested below.
Thanks
Update #2:
This is the JSON I get back from calling the page directly
{
"COLUMNS": [
"STRPOSTITLE",
"STROFFICE",
"STROTG",
"STRDEPART",
"FDREDITASSIGN1STRNR_FROM",
"FDREDITASSIGN1STRNR_TO",
"FDREDITASSIGN2NDRNR_FROM",
"FDREDITASSIGN2NDRNR_TO",
"FDREDITASSIGN3RDRNR_FROM",
"FDREDITASSIGN3RDRNR_TO",
"FDREDITASSIGN4THRNR_FROM",
"FDREDITASSIGN4THRNR_TO",
"FTAEDITASSIGNTOURCOMMENTS",
"FTAMISSIONEDITASSIGNTOURCOMMENTS"
],
"DATA": [
[
1872,
19,
"February, 20 2013 00:00:00",
"February, 19 2014 00:00:00",
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
]
]
}
Update #3: Ok I'm able to fill in the data that I want but there is still a little more work to go. I have the data filling in the proper form fields but I need to Set the drop down to match what is returned. The query returns a number. That number will match the option value of a drop down. I have been trying to find it with:
$('#PosTitle').find('option:eq(PosVar)').prop('selected', true);
But that doesn't set the value.
Thanks again!