adding Text to SVG document in javascript
I think you need to create a text node to hold the string and append that to the SVG text element.
var svgNS = "http://www.w3.org/2000/svg";
var newText = document.createElementNS(svgNS,"text");
newText.setAttributeNS(null,"x",x);
newText.setAttributeNS(null,"y",y);
newText.setAttributeNS(null,"font-size","100");
var textNode = document.createTextNode(val);
newText.appendChild(textNode);
document.getElementById("g").appendChild(newText);
There's a working example at http://old.carto.net/papers/svg/manipulating_svg_with_dom_ecmascript/.
var txt = document.createElementNS(svgNS, 'text');
txt.setAttributeNS(null, 'x', x);
txt.setAttributeNS(null, 'y', y);
txt.setAttributeNS(null,'font-size','100');
txt.innerHTML = val;
document.getElementById("g").appendChild(txt);