473,419 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Creating Form & Element Objects

I'm curious as to whether it's possible to create a Form object and
populate it with form element objects, strictly in Javascript, without
the need to apply the form to a document.

Essentially, I want to do this:

tmpFormObj = new Form();
tmpFormObj.target = document.location; // For example.
tmpFormObj.method = "POST";

tmpElementObj = new Input();
tmpElementObj.type = "text";
tmpElementObj.value = "HELLO WORLD";

.... but I'm not sure whether it's possible to insert the Element object
into the Form object. Furthermore, my Javascript seems to terminate at
the 'new Form()' statement. Is this even possible?

TIA,

- skubik.
Jul 23 '05 #1
2 2104


skubik wrote:
I'm curious as to whether it's possible to create a Form object and
populate it with form element objects, strictly in Javascript, without
the need to apply the form to a document.

Essentially, I want to do this:

tmpFormObj = new Form();
tmpFormObj.target = document.location; // For example.
tmpFormObj.method = "POST";

tmpElementObj = new Input();
tmpElementObj.type = "text";
tmpElementObj.value = "HELLO WORLD";

... but I'm not sure whether it's possible to insert the Element object
into the Form object. Furthermore, my Javascript seems to terminate at
the 'new Form()' statement. Is this even possible?


With modern browsers like IE 5/6, Netscape 6/7, Mozilla, Firefox, Opera
7 you can create any HTML element dynamically, you use the W3C DOM to do
that, there are no constructors (e.g Form, Input) as you have tried
above but there is a factory method
document.createElement
that takes the tag name as a string argument so you can do
var form, input;
if (document.createElement && (form = document.createElement('form'))) {
form.action = 'whatever.php';
form.method = 'POST';

input = document.createElement('input');
input.type = 'text';
input.name = 'inputName';
input.value = input.defaultValue = 'Kibology';

However that just creates those elements in memory, you need then to
insert one into the other and also insert the form into the document

form.appendChild(input);
document.body.appendChild(form);
}

Theoretically you could just keep the form object in memory but I doubt
that (all) browsers let you then submit such a form.
If all you want to do is post data to the server then a considerable
amount of browsers allows that using the XMLHTTP request object, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
and a link in the FAQ
<http://jibbering.com/faq/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
"skubik" <vk***@yahoo.com> skrev i meddelandet
news:cCuyd.564723$nl.93802@pd7tw3no...
I'm curious as to whether it's possible to create a Form object and
populate it with form element objects, strictly in Javascript, without
the need to apply the form to a document.

Essentially, I want to do this:

tmpFormObj = new Form();
tmpFormObj.target = document.location; // For example.
tmpFormObj.method = "POST";

tmpElementObj = new Input();
tmpElementObj.type = "text";
tmpElementObj.value = "HELLO WORLD";

... but I'm not sure whether it's possible to insert the Element object
into the Form object. Furthermore, my Javascript seems to terminate at
the 'new Form()' statement. Is this even possible?


You'll be able to do this with DOM functions - createElement(),
setAttribute(), appendChild() and so on. Your code will look something like
this:

var theForm = document.createElement("form");
theForm.action = "...";
theForm.method = "...";

var theElement = document.createElement("input");
theElement.type = "button";
....
theForm.appendChild(theElement);
....
var nodeSomewhereInDocument = .....; // using, for instance,
document.getElementById()
nodeSomewhereInDocument.appendChild(theForm);

Joakim Braun
Jul 23 '05 #3

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

Similar topics

6
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
16
by: TTroy | last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics). K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like this... "Newcomers to C are...
1
by: Thomas D. | last post by:
Hello all, I'm using the IXmlSerializable interface for a project and encounter some problems when testing my webservice in a client application. I know this interface is undocumented and not...
1
by: Mike Logan | last post by:
I have a schema that defines my messages and objects. I then have a WSDL that defines the web services. I have my sample XSD, sample WSDL, and the code generated from WSDL.exe. In the generated...
2
by: misower | last post by:
var c = document.getElementById("PanelTree"); // PanelTree is a <div> element! var n = document.createElement("div"); n.setAttribute('id', 'nu'); n.setAttribute('style',...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
32
by: Joe | last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing quite often the following (this example taken from a wiki): $wakka =& new Wakka($wakkaConfig); What exactly is the =&, and...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.