473,396 Members | 1,938 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,396 software developers and data experts.

Adding a label to a TextNode

ok, I have a TextNode:
Expand|Select|Wrap|Line Numbers
  1. var firstname_text = document.createTextNode("First Name: ");
  2.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

How would I be able to add a <label> tag to it so that when it prints out it is wrapped in the <label> tag?

Thanks!!!!
Jul 19 '07 #1
9 2137
pbmods
5,821 Expert 4TB
Heya, Nitestarz.

First, you'd need to create the label, then append your text node to it.
Expand|Select|Wrap|Line Numbers
  1. var theLabel = document.createElement('label');
  2. var firstname_text = document.createTextNode("First Name: ");
  3. theLabal.appendChild(firstname_text);
  4.  
Jul 19 '07 #2
duhh!!! thank you..my brain is slowww today
Jul 19 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

you have to create the label-node and then appendChild the textNode to it ...

your document-node is to imagine like this after you've done it:

Expand|Select|Wrap|Line Numbers
  1. <label>
  2.     |_ <textnode>
  3.  
after that ... append the label-node to your document wherever you want ...

kind regards

ps: ahh ... i see you got help during typing my post ;))
Jul 19 '07 #4
Hmmm. It doesnt seem to be adding. Here is my whole code i am using:
Expand|Select|Wrap|Line Numbers
  1. function add_student(){
  2.  
  3. ///Create Label///
  4. var label = document.createElement('label');
  5.  
  6. //// Create Line breaks ////
  7. var linebreak=document.createElement("p");
  8. var linebreak0=document.createElement("p");
  9.  
  10. //// Create text ////
  11. var header = document.createTextNode("Student Information");
  12. var firstname_text = document.createTextNode("First Name: ");
  13.  
  14. //// Create input boxes ////
  15. var StudentFirstname=document.createElement('input') ;
  16. StudentFirstname.type='text';
  17. StudentFirstname.size='45';
  18. StudentFirstname.name='Student2_Firstname';
  19.  
  20. //// Append ////
  21. document.forms.Registration.appendChild(header);
  22. document.forms.Registration.appendChild(linebreak0 );
  23. label.appendChild(firstname_text);
  24. document.forms.Registration.appendChild(firstname_text);
  25. document.forms.Registration.appendChild(StudentFirstname);
  26. }
  27.  
Jul 19 '07 #5
gits
5,390 Expert Mod 4TB
where do you append the label? ;) ... instead of appending the textnode to the document (line 24), you have to append the label, that has the textnode appended already ... when you append it now, you append the 'label+textnode-construct' ... ok?

kind regards
Jul 19 '07 #6
I think i am more confused now!
Jul 19 '07 #7
gits
5,390 Expert Mod 4TB
I think i am more confused now!
replace line 24 with:

Expand|Select|Wrap|Line Numbers
  1. document.forms.Registration.appendChild(label);
Jul 19 '07 #8
ahhh! i see how that works now! thank you :-)
Jul 19 '07 #9
gits
5,390 Expert Mod 4TB
no problem ;) ... come back when you have more questions ...

kind regards
Jul 19 '07 #10

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

Similar topics

4
by: Mateo | last post by:
Hi! I have labels on my page (some are web forms controls, and some are plain HTML labels), and I need Mozilla compatibile way for reading label value. For example, in IE I can use this:...
4
by: mscir | last post by:
When I try to use the DOM to add an image to a table cell, it works in IE but not in Netscape. If I look at the innerHTML of the table in Netscape I see %5C in place of "\" in the image file path,...
17
by: cleary1981 | last post by:
hi, I am dynamically generating a table in my application depending on what records exist in the database. The problem I am having is when I try to assign an event handler to each record. I am...
3
by: didi86 | last post by:
Please help me to adding multiple row at a time... // Last updated 2006-02-21 <script language="javascript"> function addRowToTable() { var tbl = document.getElementById('tblSample'); ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
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
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,...

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.