how to dynamically create forms in xhtml with javascript?

Discussion in 'Javascript' started by Eric Sessoms, Oct 6, 2005.

  1. Eric  Sessoms

    Eric Sessoms Guest

    I am trying to create forms on the fly in strict xhtml using
    javascript. I won't bore you with why, but I should mention that I'm
    only interested in the very latest versions of Mozilla based browsers.

    The basic problem is that the forms do not display. I've included a
    minimal sample below that illustrates this. It validates, I get no
    javascript errors at run time, and most disconcerting of all is that
    the DOM tree looks right after the page has loaded... but still


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    <html xmlns="" xml:lang="en" lang="en">
    <title>Test Page</title>
    <script type="text/javascript">
    function init() {
    var input = document.createElement('input');
    <body onload="init();">
    <form id="form" action="">
    <p><!-- The document displays if I include: <input/> --></p>
    Eric Sessoms, Oct 6, 2005
    1. Advertisements

  2. How do you serve the document to Mozilla, as text/html, or as
    application/xhtml+xml, or as application/xml or as text/xml?
    You could try with
    var input =
    instead. That should fix it if you serve as application/xml or text/xml
    which might be the problem.
    Martin Honnen, Oct 6, 2005
    1. Advertisements

  3. Eric  Sessoms

    Eric Sessoms Guest

    Damn, you're good. And fast. Yes, I was serving it as text/xml and
    your suggestion fixed the problem. Thanks very much!
    Eric Sessoms, Oct 6, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.