473,480 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to dynamically create forms in xhtml with javascript?

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).appendC hild(input);
}
]]>
</script>
</head>
<body onload="init();">
<form id="form" action="">
<p><!-- The document displays if I include: <input/> --></p>
</form>
</body>
</html>

Oct 6 '05 #1
2 1775


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/
Oct 6 '05 #2
Damn, you're good. And fast. Yes, I was serving it as text/xml and
your suggestion fixed the problem. Thanks very much!

Oct 6 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
1788
by: Nick | last post by:
Right now I'm using document.write("<script language='javascript' src='jsFile" + i + ".js'></script>"); It works -- I have a lot of data in each file and only want the visitor to have to...
5
3710
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
3
7979
by: Greg Scharlemann | last post by:
I'm not sure the best way to accomplish this... my hunch is with javascript, but I'm not sure if using server side code (PHP) would be easier. I'm adding people to a database. People have a...
5
3082
by: cyprian | last post by:
how do i use javascript function to dynamically insert text into textarea from the result of an array comparison expression. read the dom but found no way out. thanks
0
7044
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.