JSON data not pulling through for textarea input control

102 views Asked by At

I am currently trying to build up some html via javascript and when I try to assign the value attribute of my textarea input control it does not seem to want to pull through, the textarea becomes blank when loaded. Values seem to pull through for normal text type input. I have also stepped through the javascript code and made sure the JSON data I was getting actually had a value in it, which it did.

function BuildDeviceInfoHTML(data) {
var divFormGroupOpening = '<div class="form-group">';
var divOpeningInput = '<div class="col-md-10">'
var result;

var deviceName = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceName">Device Name: </label>' +
    divOpeningInput +
    '<input id="deviceName" class="form-control" type="text" value="' + data.devices[0].deviceName + '" name="deviceName" data-val-required="Device name is required" data-val="true">'
    + '</div></div>';

var deviceDisplay = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceDisplay">Displayed as: </label>' +
    divOpeningInput +
    '<input id="deviceDisplay" class="form-control" type="text" value="' + data.devices[0].deviceDisplay + '" name="deviceDisplay" data-val="false">'
    + '</div></div>';

var deviceDesc = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceDisplay">Displayed as: </label>' +
    divOpeningInput +
    '<textarea id="deviceDesc" class="form-control" value="' + data.devices[0].deviceDesc + '" name="deviceDesc"  data-val="false"></textarea>'
    + '</div></div>';

result = deviceName + deviceDisplay + deviceDesc;

return result
}
1

There are 1 answers

3
GUL On BEST ANSWER

Textarea hasn't value attribute. You should put content inside tag:

<textarea>VALUE HERE</textarea>

You should modify last part of your code in:

var deviceDesc = divFormGroupOpening + 
  '<label class="col-md-2 control-label" for="deviceDisplay">
  Displayed as: </label>' + divOpeningInput +
  '<textarea id="deviceDesc" class="form-control" name="deviceDesc" 
  data-val="false">' + data.devices[0].deviceDesc + '</textarea>'
  + '</div></div>';