0

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
  • How about the other inputs are both for output or inputs ? also which js library you use? Commented Jun 14, 2015 at 13:18

1 Answer 1

2

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>';
Sign up to request clarification or add additional context in comments.

3 Comments

When doing a HTTP POST would there be any problems? e.g. It won't retrieve the value
There won't be any problem, textarea works that way. When you submit the form you'll get the value inside it
That's worked like a treat and thanks for answering the second question I had.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.