Hello,
I need to know how to create closing tag elements when using DOM to add in form elements to a page.
Here is the code...the <div> I am adding to the page is called dropDownList (for legacy reasons...it isnt really a drop down list!).
I need to put in closing td tags...
I tried this: - var tdClose = document.createElement(/td);
and this: - var td = document.createElement('/td');
but when I try and add them e.g. - document.getElementById('dropDownList').appendChild(tdClose);
I get errors.
Help ! - function addRaresToList(number){
-
var species = document.getElementById('addSpecies').value;
-
alert ("ADD " + species + " to " + number);
-
-
var td = document.createElement(td);
-
-
// add hidden index
-
var i = document.createElement('input');
-
i.type = 'hidden';
-
i.name = 'observation.index';
-
i.value = 'number';
-
document.getElementById('dropDownList').appendChild(i);
-
-
// add hidden comment
-
var i = document.createElement('input');
-
i.type = 'hidden';
-
i.name = 'observation.number.comment';
-
i.id = 'observation.number.comment';
-
document.getElementById('dropDownList').appendChild(i);
-
-
// add hidden breeding code
-
var i = document.createElement('input');
-
i.type = 'hidden';
-
i.name = 'observation.number.breedingCode';
-
i.id = 'observation.number.breedingCode';
-
document.getElementById('dropDownList').appendChild(i);
-
-
// add species name
-
document.getElementById('dropDownList').appendChild(td);
-
var txt = document.createTextNode(species);
-
document.getElementById('dropDownList').appendChild(txt);
-
-
-
// add checkbox
-
document.getElementById('dropDownList').appendChild(td);
-
var i = document.createElement('input');
-
i.type = 'checkbox';
-
i.name = 'observation.number.species';
-
var d = document.getElementById( 'dropDownList' );
-
d.appendChild( i );
-
-
// add textbox
-
document.getElementById('dropDownList').appendChild(td);
-
var i = document.createElement('input');
-
i.type = 'text';
-
i.name = 'observation.number.speciesCode';
-
i.size = '7';
-
i.maxlength = '7';
-
var d = document.getElementById( 'dropDownList' );
-
d.appendChild( i );
-
-
}
-
</script>
4 3787 acoder 16,027
Recognized Expert Moderator MVP
You don't need a closing tag. The object is created and you can append it to the row and append elements/items to it.
You don't need a closing tag. The object is created and you can append it to the row and append elements/items to it.
I am still a bit confused..
Do I need to make a table in my javascript ?
At the moment all the elements I am adding in are going into just one cell of a table (I am adding my <div> to an existing table). I want each element (text, checkbox, input text) to go into a separate cell.
Surely to do that I need to put a </td> in somewhere...and I can't do this: - var tdClose= document.createElement('/td');
-
document.getElementById('dropDownList').appendChild(tdClose);
by 'the object is created' do you mean the var d = document.getEle mentById( 'dropDownList' ); object ? Sorry to be so dim, I am very new to this !
thanks for your input
gits 5,390
Recognized Expert Moderator Expert
hi ...
nope ... when using createElement it creates a valid node for you. when you append another node to it, it will be a childNode of it ... so you don't need to create a closing tag. you are not creating tags! but nodes with this dom-method.
kind regards
ps: may be the following small graph is of help ... imagine a document as a tree: - html - root node (starts with <html> and ends with </html>)
-
|_ head
-
|_ body
-
|_ div1
-
|_ div2
-
|_ whatever nodes ...
epots9 1,351
Recognized Expert Top Contributor
hi ...
nope ... when using createElement it creates a valid node for you. when you append another node to it, it will be a childNode of it ... so you don't need to create a closing tag. you are not creating tags! but nodes with this dom-method.
kind regards
ps: may be the following small graph is of help ... imagine a document as a tree: - html - root node (starts with <html> and ends with </html>
-
|_ head
-
|_ body
-
|_ div1
-
|_ div2
-
|_ whatever nodes ...
Gits is right, i think you might have confused document.write and document.create Element.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bryan |
last post by:
Hi All:
I'm trying to find the right Regexp string to remove empty SPAN tags
from an HTML string.
Say I have a string like so, and I want to remove the empty span tags:
<span>This is my text</span>
A simple expression like this /<SPAN>(.*)?<\/SPAN>/gi will give me the
|
by: MickG |
last post by:
Hi,
I am trying to validate these values, this seems to work fine for the
phone number and name but I am trying to get the program to fail to
submit and set the focus on the date when 2006 is selected and
submitted.
Thanks in advance for any help.
|
by: Heinz Willi Wiedow |
last post by:
Hey XML-Fans,
I transform some XML-Files with XmlT to html.
I want to have a DOCTYPE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
by: samikdut |
last post by:
Cannot view the output of ascx file in Netscape but can view all in IE and Opera.
Please suggest !
Thanx in advance
Samik.
|
by: dwergkees |
last post by:
Hi,
Got a litte problem here. I'm trying to create a XSLT file that will do
a transformation from WordML format (MS Word XML format, see
http://rep.oio.dk/Microsoft.com/officeschemas/welcome.htm) to a
reasonably clean (X)HTML format.
(The reason being that, combined with some PHP scripting it should be
possible to store the embedded images, which is pretty neat).
| |
by: mikepmyers |
last post by:
I've done some research online and turned up with results that did not sit well with me. I’m using the System.Xml.XslCompiledTransform class as recommended by MS; however, it’s creating self-closing tags that I don’t want, example:
* My XSLT has: <script language="javascript" src="client_scripts/VehInInv.js"></script>
* Using the XslCompiledTransform class I get: <script language="javascript" src="client_scripts/VehInInv.js"/> -- notice...
|
by: getsanjay.sharma |
last post by:
Hello all, I have been trying to implement a script using which when
the user clicks on one of the two span tags, its text is highlighted
while the same happens when the user clicks on the second one, except
that the first one loses its highlight. I am at a loss as to why this
code doesn't work.
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
|
by: David Cartwright |
last post by:
Hi,
I have a VB.NET (VS2005, .NET 2.0) application producing an XML file which
is then used by a third-party product. It turns out the latter doesn't like
self-closing tags (i.e. it would rather see <CardNo></CardNothan <CardNo
/>).
Is there a simple way to tell the XMLDocument to use the "traditional" way
of showing an empty tag instead of always saving self-closing tags?
|
by: Nathan Sokalski |
last post by:
I am using the System.Web.UI.HtmlTextWriter, and would like to create tags
that are self-closing (such as <tagname />). The RenderBeginTag method does
not offer the option of making a self-closing tag (I think it should have an
optional boolean parameter to specify whether it is self-closing, but it
doesn't). I know how to make self-closing tags using the Write methods, but
this requires calling a write method for every attribute and style,...
|
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...
|
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,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |