473,657 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting textnode or table inside FORM tag

I have a form on a page that has several textareas, and textboxes
inside a table (so the table containing the textboxes is also inside
the FORM tag).

I want to replace the textareas with simple text instead. But I want
to keep the format of my page EXACTLY the same. However, the problem
is that ...

1) Javascript won't let me create say a one-cell TABLE containing some
text (e.g. textarea's value) and then insertBefore an element in the
form. This is so because the a TABLE element is not compatible to be a
FORM's child.

2) I surely can insert a text node or a table using appendChild or
insertBefore on document.body. However, like I said I must maintain
the formatting of my page, so I again can not do this. Reason being
that the document.body won't have access to anything that's inside the
FORM tag and can only insert before or after the FORM tag.

e.g.

<BODY>
<P id="para1">foo </P>
<FORM id=form1">
<!-- anything in here is Form's property NOT body's -->
<input type="text" name="name" id="txtbox1">
</FORM>
</BODY>

So the following code is invalid:

var tNode = document.create TextNode ("hello");
document.body.i nsertBefore (tNode,
document.forms[0].getElementsByT agName ("txtbox1")) ;

because I can't insert a textnode before a form element using a body
method.
And following code is valid but not what I want according to my second
point above:

var tNode = document.create TextNode ("hello");
document.body.a ppendChild (tNode);
How can I insert a text node or table containing text inside FORM
tags?
Jul 23 '05 #1
2 2906
Asad wrote:
I have a form on a page that has several textareas, and
textboxes inside a table (so the table containing the
textboxes is also inside the FORM tag).
As it must be.
I want to replace the textareas with simple text instead.
if(document.cre ateTextNode && document.getEle mentById){
var tNode = document.create TextNode ("hello");
var txtArea = document.getEle mentById("txtbo x1");
if((tNode)&&
(txtArea)&&
(txtArea.parent Node)&&
(txtArea.parent Node.replaceChi ld)
){
txtArea.parentN ode.replaceChil d(tNode, txtArea);
}
}
But I want to keep the format of my page EXACTLY the
same. However, the problem is that ... 1) Javascript won't let me create say a one-cell TABLE
containing some text (e.g. textarea's value) and then
insertBefore an element in the form. This is so because
the a TABLE element is not compatible to be a
FORM's child.
Tables are completely compatible with being a child of a form. You are
getting confused about the DOM tree structure. The form control
(textarea) within a table is a descendent of the form, but it is a child
of its containing TD element, and it would be the insertBefore method of
that TD element that would need to be called in order to insert anything
before the textarea. (Though your stated goal is to replace the textarea
so insertBefore doesn't sound like the method to be using).
2) I surely can insert a text node or a table using
appendChild or insertBefore on document.body. However,
like I said I must maintain the formatting of my page,
so I again can not do this. Reason being that the
document.body won't have access to anything that's inside
the FORM tag and can only insert before or after the FORM
tag.
In your example the only child of the BODY is the FORM. The TEXTAREA is
a child of the FORM.
e.g.

<BODY>
<P id="para1">foo </P>
<FORM id=form1">
<!-- anything in here is Form's property NOT body's -->
<input type="text" name="name" id="txtbox1">
</FORM>
</BODY>

So the following code is invalid:

var tNode = document.create TextNode ("hello");
document.body.i nsertBefore (tNode,
document.forms[0].getElementsByT agName ("txtbox1")) ; ^^^^^^^^^^^^^^^ ^^^^^
The getElementsByTa gName method returns a - nodeList - object not a
Node, it is expecting its argument to be a tag name, which may have been
"TEXTAREA" in this case.

But more likely you should refer to an IDed textarea with:-

document.getEle mentById("txtbo x1")

- or -

document.forms[0].elements['txtbox1']

- or -

document.forms['form1'].elements['txtbox1']

If you insist on using getElementsByTa gName you need to pass the tag
name as an argument (eg 'TEXTAREA') and then index the textarea element
in question from the returned nodeList:-

document.forms[0].getElementsByT agName ("TEXTAREA")[0]

Then you have the problem with using the insertBefore method on the BODY
element. The textarea is not a child of the BODY element so that method
is specified as throwing a NOT_FOUND_ERR exception when it turns out
that its second argument is not one of its children.
because I can't insert a textnode before a form element
using a body method.
You probably can, but you don't appear to have tried to do that yet, and
it is not what you want to do anyway.
And following code is valid but not what I want according
to my second point above:

var tNode = document.create TextNode ("hello");
document.body.a ppendChild (tNode);
How can I insert a text node or table containing text
inside FORM tags?


Using the insertBefore or appendChild methods of the FORM element, but
that is still not what you want to do. To replace the textarea Element
with a text Node use the code I listed above (first).

Richard.
Jul 23 '05 #2
"Richard Cornford" <ri*****@litote s.demon.co.uk> wrote in message
news:c9******** **@hercules.bti nternet.com...
Asad wrote:
I have a form on a page that has several textareas, and
textboxes inside a table (so the table containing the ^^^^^^^^^ textboxes is also inside the FORM tag). <snip> <BODY>
<P id="para1">foo </P>
<FORM id=form1">
<!-- anything in here is Form's property NOT body's -->
<input type="text" name="name" id="txtbox1">
</FORM>
</BODY> <snip> document.forms[0].getElementsByT agName ("txtbox1")) ;
<snip> document.forms[0].getElementsByT agName ("TEXTAREA")[0]

<snip>
For text boxes (<input type="text">) that would be:-

document.forms[0].getElementsByT agName ("INPUT")[0]

-everything else would be the same.

Richard.
Jul 23 '05 #3

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

Similar topics

0
2424
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish, Swedish or English). There are about a dozen tables with columns that need localization. Doing this in the application level was a no-goer. It would have taken far too much time (there is a *lot* of code and unfortunately most of the...
12
4891
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
8
7151
by: L Major | last post by:
Hi Unfortunately, I am limited to using tables for part of my current project. I have a form that spans across a number of TR and TD in the shape of checkboxes. Doctype is XHTML 1.0 Transitional, Encoding is utf-8 Is there anything wrong? Should I try something else? What in that case?
1
2449
by: Ben | last post by:
Hi all, I'm trying to write inside a table cell from external javascript but am not successful. When I insert inside a form within <td...>, it works but does not work for normal table cell. My codes are as follows; please read comments on the code: index.html ---------- <html>
4
1764
by: cassey14 | last post by:
Hi! I am having a problem here..I have a form and in that form I have a subform..Inside that subform it has data..I wanted to insert that data in a table..is it possible?please help me.. tank you in advance! -cassey
5
2021
by: bob44 | last post by:
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and then if I try inserting another record, the new one is not seen in the database. There is no error messages seen in the form when entering a new record. Heres the code for the form <html> <head> </head> <center> <form method="post"...
10
2573
by: jmartmem | last post by:
Greetings, I have an ASP page with a 5x5 table embedded inside an Insert Record Form. This table contains several fields (mostly drop down list menus) and is used for corporate timekeeping (users record their daily hours by making selections from the list menus). My challenge is to figure out how the user can complete all rows of the table and click one button to submit the entire form AND have each row inserted as a unique record. In...
2
3075
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
1
4595
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1607
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.