I am trying to create an array of simple text inputs inside an SVG that is created dynamically using javascript.
First I was doing it in PHP and there the snippet would look like this:
for ($row=0; $row<7; $row++)
{
for ($col=0; $col<7; $col++)
{
$fx=130+100*$col;
$fy=120+100*$row;
echo "<foreignObject x="".$fx."" y="".$fy."" width="50" height="80">\n<body xmlns="http://www.w3.org/1999/xhtml">\n<form><input type="text" width="1"/ style="font-size:48px; border:none;"></form>\n</body>\n</foreignObject>";
}
}
Then in javascript I would try it for a single instance like this but I did not get this to work.
var field = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
field.setAttribute("x", "130");
field.setAttribute("y", "120");
field.setAttribute("width", "50");
field.setAttribute("height", "80");
mySvg.appendChild(field.cloneNode(true));
var s = '<body xmlns="http://www.w3.org/1999/xhtml"><form><input type="text" width="1" style="font-size:48px; border:none;"></form></body>';
var s1 = document.createElement(s);
field.appendChild(s1);
</script>
Any hints? Or should I switch to a completely different implementation (e.g. CSS)?