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
    nothing.

    Help!

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Test Page</title>
    <script type="text/javascript">
    <![CDATA[
    function init() {
    var input = document.createElement('input');
    document.getElementsByTagName('p').item(0).appendChild(input);
    }
    ]]>
    </script>
    </head>
    <body onload="init();">
    <form id="form" action="">
    <p><!-- The document displays if I include: <input/> --></p>
    </form>
    </body>
    </html>
    Eric Sessoms, Oct 6, 2005
    #1
    1. Advertising

  2. Eric Sessoms wrote:

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


    How do you serve the document to Mozilla, as text/html, or as
    application/xhtml+xml, or as application/xml or as text/xml?

    > var input = document.createElement('input');


    You could try with
    var input =
    document.createElementNS(
    'http://www.w3.org/1999/xhtml',
    'input'
    );
    instead. That should fix it if you serve as application/xml or text/xml
    which might be the problem.




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 6, 2005
    #2
    1. Advertising

  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
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    876
  2. chronos3d
    Replies:
    9
    Views:
    771
    Andy Dingley
    Dec 5, 2006
  3. Usha2009
    Replies:
    0
    Views:
    1,128
    Usha2009
    Dec 20, 2009
  4. xhtml champs
    Replies:
    0
    Views:
    519
    xhtml champs
    Aug 1, 2011
  5. xhtml champs
    Replies:
    0
    Views:
    1,028
    xhtml champs
    Aug 2, 2011
Loading...

Share This Page