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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.