How can I set value in select option using jquery dynamically?

How can I set value in select option using jquery dynamically?

Below I am giving the snapshot of my code .Here i am facing the problem because in some dropdown value is set using below code but some dropdown is not setting please verify where am I going wrong.


    function templateLoading(value){
alert(value);
$.ajax({
type : "GET",
contentType : "application/json",
url : "templateload.ank?name="+value,
dataType : 'json',
success : function(data) {
alert(data);
$.each(data,function(key, val) {
//alert("fc"+"'"+key+"'");
if(key=="fileHeaderAvailbale"){
alert(key +"fileHeaderAvailbale");

}
//in key -->dynamically component id is coming and in the "value" value is coming which previous i set .I want to set all these previous value to related component by using id which is coming through key. 

$("#"+key).val(val);
//document.getElementById(key).value=val;
});
console.log("SUCCESS: ", data);
},
error : function(e) {
//document.getElementById("FooterConstant").value= "rama";  
console.log("ERROR: ", e);
},
})
}
My Html Code is below. This Html Code belong to problem page which is showing in image at last in the code or you paste below link in url then You get the problem screen shot .In image i indicate where value is not setting.






<fieldset>
<legend>Header Details tab Configuration</legend>

<table style="width: 100%">
<tr>
<td><label for="fheader">File Header Available: </label></td>
<td><select id="fileHeaderAvailbale" onchange="fileHeaderAvail(value);" name="fheader">
<option value="default">Select</option> 
<option value="YES">YES</option>
<option value="NO">NO</option>
</select></td>

<td><label for="dupHeader">Duplicate Check Header:</label></td>
<td><select id="duplicateCheckHeader" disabled="disabled" name="dupHeader">
<option value="default">Select</option>
<option value="YES">YES</option>
<option value="NO">NO</option>
</select></td>

<td><label for="mlHeader">MultiLine Header: </label></td>
<td><select id="multilineHeader"
onchange="multiLineHeaderAvail(value);" disabled="disabled" name="mlHeader">
<option value="default">Select</option>
<option value="YES">YES</option>
<option value="NO">NO</option>
</select></td>


</tr>

<tr>
<td><label for="headerType">Header Key Type:</label></td>
<td><select id="headerKeyType"
onchange="multipleHeaderDataCountSet(value);" disabled="disabled" name="headerType">
<option value="default">Select</option>
<option value="SingleHeaderKey">SingleHeaderKey</option>
<option value="MultipleHeaderKey">MultipleHeaderKey</option>
</select></td>

<td><label for="mheaderDataCount">Multiple Header
Data Count: </label></td>
<td><input id="multipleHeaderDataCount" name="mheaderDataCount"
type="text" class="required" disabled="disabled"></td>


<td><label for="lnkItem">Link Item changes to link</label></td>

<td><a href="#" id="lnkItem">Header Details</a></td>

</tr>


<tr>
<td><label for="lineHeaderRecord">Line Between Header
and Data Record: </label></td>
<td><input id="lineBetweenHeaderData" name="lineHeaderRecord"
type="text" class="required"></td>

<td><label for="headerSequenceCheck">Header Sequence
Check Applicable: </label></td>
<td><select id="headerSequenceCheck" disabled="disabled"
onchange="hdrSeqChkApplicable(value);" name="headerSequenceCheck">
<option value="default">Select</option>
<option value="YES">YES</option>
<option value="NO">NO</option>
</select></td>

<td><label for=headerSequenceFormat> Header Sequence
Format: </label></td>
<td><input id="headerSequenceFormat"
name="headerSequenceFormat" type="text" class="required"
disabled="disabled"></td>

</tr>

<tr>
<td><label for="dataRecord">Data Record Between
Header:</label></td>
<td><input id="datarecordBetweenHeader" name="dataRecord" type="text"
disabled="disabled" class="required"></td>

<td><label for="headerAvail">Header Tag Available :</label></td>
<td><select id="headerTagAvailbale"
onchange="headerTagAvail(value);" disabled="disabled" name="headerAvail">
<option value="default">Select</option>
<option value="YES">YES</option>
<option value="NO">NO</option>
</select></td>

<td><label for=headerTagName> Header Tag Name: </label></td>
<td><input id="headertagName" name="headerTagName"
disabled="disabled" type="text" class="required"></td>

</tr>

<tr>
<td><label for=childTagCount> Header Child Tag Count:
</label></td>
<td><input id="headerChildTagCount" name="childTagCount"
disabled="disabled" type="text" class="required"></td>



<td><label for=dataElement>Header Data Element: </label></td>
<td><input id="headerdataElement" name="dataElement" type="text"
disabled="disabled" class="required"></td>

</tr>

</table>
</fieldset>

  





And data is coming in JSOn format like below.


    {"fileName":"IRIS","sequenceNumber":0,"constvalue":"12","databeginCheck":"Yes","databeginConst":"NO","datarecordBetweenHeader":"13","datarecordConst":"Yes","datawithMulticonst":"50","defineConst":"asd","delimeter":",","duplicateCheck":"YES","duplicateCheckHeader":"","fileBeginWith":"IRIS2015","fileBeginWithCheck":"YES","fileHeaderAvailbale":"Yes","fileId":0,"fileLocation":"Local","fileNameConvention":"DD:MM:yyyy","fileNameConventionCheckApplicable":"NO","fileNameLength":"15","filePath":"D://IRIS/2015/ABC","fileShortName":"IRIS125","fileType":"Delimited","filefooterAvailable":"YES","filefooterWithConst":"YES","footerConst":"asdfg","footerFormat":"YYMMDDHHMI","footerFormateCheck":"YYMMDDHHMI","footerLength":"16","footerType":"FixedLength","headerChildTagCount":"No","headerKeyType":"asce","headerSequenceCheck":"No","headerSequenceFormat":"3","headerTagAvailbale":"12","headerdataElement":"uihk","headertagName":"Yes","lineBetweenFooterData":"15","lineBetweenHeaderData":"MultipleHeaderKey","linebetweenDataRecord":"14","multilineHeader":"No","multilineRecordCheck":"NO","multipleHeaderDataCount":"15","noTagcontrol":"15","numberConstant":"01","numberLine":"41","numberOfColumns":"10","recordcountLine":"Yes","selectResources":"null"}

And my screen is below ,I commented where the value is not setting.Below I provide link of my image please click on this screen shot and tell me where i am going  wrong. 

[Click here to see Screen shot of the problem.][1]





thanks & regards,
shivam