We have a JSON response which can contain null values (e.g. { myValue: null }) - we assign this value to a textbox on a form: (actually, we use JQuery, but this is equivalent
var nullString = null;
document.getElementById('myInput').value = nullString;
If we assign this value to an HTML textbox value, the behaviour seems browser-dependent:
Firefox and Chrome both display an empty text box, and when you read 'value' back you get null.
IE puts the string 'null' into the text box, and when you read 'value' back, you get the string "null" (i.e. setting 'value' and reading it back has modified the data)
(It's here: http://jsbin.com/uleno/edit if anyone wants to try it)
Which browser is doing the right thing here, or is this undefined behaviour? And is there a cleverer more elegant workaround than doing a lot of (myValue == null ? '' : myValue) stuff?