473,748 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with closing tags for DOM, Javascript

12 New Member
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:
Expand|Select|Wrap|Line Numbers
  1.   var tdClose = document.createElement(/td);
and this:
Expand|Select|Wrap|Line Numbers
  1.   var td = document.createElement('/td');
but when I try and add them e.g.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('dropDownList').appendChild(tdClose);
I get errors.

Help !


Expand|Select|Wrap|Line Numbers
  1. function addRaresToList(number){
  2.   var species = document.getElementById('addSpecies').value;
  3.   alert ("ADD " + species + " to " + number);
  4.  
  5.   var td = document.createElement(td);
  6.  
  7.   // add hidden index
  8.   var i = document.createElement('input');
  9.   i.type = 'hidden';
  10.   i.name = 'observation.index';
  11.   i.value = 'number';
  12.   document.getElementById('dropDownList').appendChild(i);
  13.  
  14.   // add hidden comment
  15.   var i = document.createElement('input');
  16.   i.type = 'hidden';
  17.   i.name = 'observation.number.comment';
  18.   i.id = 'observation.number.comment';
  19.   document.getElementById('dropDownList').appendChild(i);
  20.  
  21.   // add hidden breeding code
  22.   var i = document.createElement('input');
  23.   i.type = 'hidden';
  24.   i.name = 'observation.number.breedingCode';
  25.   i.id = 'observation.number.breedingCode';
  26.   document.getElementById('dropDownList').appendChild(i);
  27.  
  28.   // add species name  
  29.   document.getElementById('dropDownList').appendChild(td);
  30.   var txt = document.createTextNode(species);
  31.   document.getElementById('dropDownList').appendChild(txt);
  32.  
  33.  
  34.   // add checkbox
  35.   document.getElementById('dropDownList').appendChild(td);
  36.   var i = document.createElement('input');
  37.   i.type = 'checkbox';
  38.   i.name = 'observation.number.species';
  39.   var d = document.getElementById( 'dropDownList' );
  40.   d.appendChild( i );
  41.  
  42.   // add textbox
  43.   document.getElementById('dropDownList').appendChild(td);
  44.    var i = document.createElement('input');
  45.    i.type = 'text';
  46.    i.name = 'observation.number.speciesCode';
  47.    i.size = '7';
  48.    i.maxlength = '7';
  49.    var d = document.getElementById( 'dropDownList' );
  50.    d.appendChild( i );  
  51.  
  52. }
  53. </script>
Sep 28 '07 #1
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.
Sep 28 '07 #2
basm101
12 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. var tdClose= document.createElement('/td');
  2.  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
Sep 28 '07 #3
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:

Expand|Select|Wrap|Line Numbers
  1. html - root node (starts with <html> and ends with </html>)
  2.   |_ head
  3.   |_ body
  4.         |_ div1
  5.         |_ div2
  6.               |_ whatever nodes ...
Sep 28 '07 #4
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:

Expand|Select|Wrap|Line Numbers
  1. html - root node (starts with <html> and ends with </html>
  2.   |_ head
  3.   |_ body
  4.         |_ div1
  5.         |_ div2
  6.               |_ whatever nodes ...
Gits is right, i think you might have confused document.write and document.create Element.
Sep 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1628
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
6
4851
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.
2
2199
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">
6
1165
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.
4
1802
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).
1
8029
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...
11
599
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"> <!--
4
11165
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?
1
5140
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,...
0
8996
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
8832
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
9562
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
9386
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 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...
0
9254
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
8255
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
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
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.