extrovertive Posted November 13, 2006 Share Posted November 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 13, 2006 Share Posted November 13, 2006 The error you're getting is from trying to add document.getElementById(elem) to the line break. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted November 13, 2006 Author Share Posted November 13, 2006 Ok, what would be the solution to this? Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 13, 2006 Share Posted November 13, 2006 Just flip it around: document.getElementById(elem).appendChild(newBreak); You could even drop the newBreak and use document.getElementById(elem).appendChild(document.createElement("br")); Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 13, 2006 Share Posted November 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
extrovertive Posted November 13, 2006 Author Share Posted November 13, 2006 You're right. I just check my sources, and I do not see <br> at all. I guess that's fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.