set value in select option using jquery dynamically
by Akram kamal
HTML
<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...
JavaScript
var data = {
"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"
}
$(function() {
$.each(data, function(key, val) {
var field=$("#"+key).val(val)
if (field.length!==1)
console.log("missing",key, val)
else if (field.val() !== val)
console.log("can't set",key,val)
})
})