Jump to content

Adding a "<br />" after a dynamic text form element?


extrovertive

Recommended Posts

I have but I get an error.

[code]
function AddTextButton(elem)
{
  var newText = document.createElement("input");
  newText.setAttribute("type", "text");
  newText.setAttribute("name", "TB[]");
  document.getElementById(elem).appendChild(newText);
  var newBreak = document.createElement("br");
  newBreak.appendChild(document.getElementById(elem));
   
}
[/code]

Of course, I want my <input type="text" name="TB[]" /><br /> to be XHTML valid, but I would I go at dynamically creating an input text with a break at the end?
As for the self closing tags, I avoiding answering it because I wasn't sure if there wasn't some obscure (at least to me) method you could use in place of createElement().  I spent some time googling on it last night but didn't find anything, though I did discover document.createElementNS() which seems to only be useful in standards browsers when you use an xhtml-xml DTD, and even that just gave it an xml namespace (hence the NS) without the self-closing; all I got through view selection source was regular html <[i][/i]br> and <[i][/i]input> tags.  IMHO I would say that if even a method which is meant specifically for that standard doesn't generate tags that meet it, the only option would be to use the innerHTML property to use the correct tags inside a string.  What I still can't say is whether it really matters; the page will still validate in its original state.  There are far better people here than I, but for a quicker answer, that's the best information I can give you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.