473,805 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.getEle mentById / appendChild

Hi, I'm having a problem utilizing the DOM. I tried using my own
code, but it wasn't working, so I tried to use code straight from
another web site and it verified that the problem may not be mine. I
am using IE 6.0.28 (sp5) on a Windows 2000 Server.

I am very new to DOM so I'm not ruling out that I'm doing something
wrong. However, I am posting the code that I got from another site
because I did notice that the examples were using Netscape. I'm
curious to know if there are differences between Netscape and IE for
DOM? Anyway the site that the code came from is
http://www-106.ibm.com/developerwork...jsdom/#figure2
and seems like it should work. I'm hoping somebody can help. Thank
you in advance.... Chris

<%@ Language=VBScri pt %>
<html>
<head>
<title>Gettin g Sticky</title>
<style type="text/css">
* {font-family: sans-serif}
a {font-size: 6pt}
.editButton {font-size:6pt}
</style>

<script type="text/javascript">
function getCurrentNumbe r() {
formElement = document.getEle mentById("noteF orm");
return formElement.chi ldNodes.item(1) .value;
}

function makeNewNote(){
mainDivElement = document.getEle mentById("mainD iv");
newNote = document.create Element("div");
newNote.setAttr ibute("id", "note"+getCurre ntNumber());
mainDivElement. appendChild(new Note);
noteForm.total. value= parseInt(noteFo rm.total.value) + 1;
}
</script>
</head>
<body>
<div id="mainDiv" style="height:8 5%; width:85%; border:3px solid
red;
padding: 10px; z-index:
-100" >

<h1>Getting Sticky</h1>

<form id="noteForm">
Current number of notes
<input type="text" name="total" value="0"size=" 3"/>
<input type="button" value="Add a new note"
onclick="makeNe wNote()" />
</form>
<div id="addhere"> </div>

</div>
</body>
</html>

Jul 20 '05 #1
2 22235


Chris wrote:
Hi, I'm having a problem utilizing the DOM. I tried using my own
code, but it wasn't working, so I tried to use code straight from
another web site and it verified that the problem may not be mine. I
am using IE 6.0.28 (sp5) on a Windows 2000 Server.

I am very new to DOM so I'm not ruling out that I'm doing something
wrong. However, I am posting the code that I got from another site
because I did notice that the examples were using Netscape. I'm
curious to know if there are differences between Netscape and IE for
DOM? Anyway the site that the code came from is
http://www-106.ibm.com/developerwork...jsdom/#figure2
and seems like it should work. I'm hoping somebody can help. Thank
you in advance.... Chris

<%@ Language=VBScri pt %>
<html>
<head>
<title>Gettin g Sticky</title>
<style type="text/css">
* {font-family: sans-serif}
a {font-size: 6pt}
.editButton {font-size:6pt}
</style>

<script type="text/javascript">
function getCurrentNumbe r() {
formElement = document.getEle mentById("noteF orm");
return formElement.chi ldNodes.item(1) .value;
Using childNodes is a potential problem as IE for instance keeps only
element nodes in childNodes while it throws out white space text nodes
between element nodes. Netscape however keeps the white space text nodes
in the DOM and therefore an expression like
element.childNo des.item(1)
is probabably selecting a different node in IE and Netscape. }

function makeNewNote(){
mainDivElement = document.getEle mentById("mainD iv");
newNote = document.create Element("div");
newNote.setAttr ibute("id", "note"+getCurre ntNumber());
mainDivElement. appendChild(new Note);
noteForm.total. value= parseInt(noteFo rm.total.value) + 1;
}
</script>
</head>
<body>
<div id="mainDiv" style="height:8 5%; width:85%; border:3px solid
red;
padding: 10px; z-index:
-100" >

<h1>Getting Sticky</h1>

<form id="noteForm">
Current number of notes
<input type="text" name="total" value="0"size=" 3"/>
<input type="button" value="Add a new note"
onclick="makeNe wNote()" />
</form>
<div id="addhere"> </div>

</div>
</body>
</html>


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:
Chris wrote:
Hi, I'm having a problem utilizing the DOM. I tried using my own
code, but it wasn't working, so I tried to use code straight from
another web site and it verified that the problem may not be mine. I
am using IE 6.0.28 (sp5) on a Windows 2000 Server.

I am very new to DOM so I'm not ruling out that I'm doing something
wrong. However, I am posting the code that I got from another site
because I did notice that the examples were using Netscape. I'm
curious to know if there are differences between Netscape and IE for
DOM? Anyway the site that the code came from is
http://www-106.ibm.com/developerwork...jsdom/#figure2
and seems like it should work. I'm hoping somebody can help. Thank
you in advance.... Chris

<%@ Language=VBScri pt %>
<html>
<head>
<title>Gettin g Sticky</title>
<style type="text/css">
* {font-family: sans-serif}
a {font-size: 6pt}
.editButton {font-size:6pt}
</style>

<script type="text/javascript">
function getCurrentNumbe r() {
formElement = document.getEle mentById("noteF orm");
return formElement.chi ldNodes.item(1) .value;


Using childNodes is a potential problem as IE for instance keeps only
element nodes in childNodes while it throws out white space text nodes
between element nodes. Netscape however keeps the white space text nodes
in the DOM and therefore an expression like
element.childNo des.item(1)
is probabably selecting a different node in IE and Netscape.


I can't remember who pointed me to this, but here is a good resource on the
"problem" described above.

<url: http://www.mozilla.org/docs/dom/technote/whitespace/ />

Using "nodomws.js " supplied there, you could re-write the function as:

function getCurrentNumbe r() {
formElement = document.getEle mentById("noteF orm");
var theNode = node_before(nod e_after(formEle ment.childNodes .item(1)));
if (theNode != null) {
return theNode.value;
} else {
return '';
}
}

and it will work in both IE and Mozilla, regardless of whitespace
distribution. It messes things up a little because it makes
childNodes.item (1) the first element in the form (when it should really be
childNodes.item (0)), but a simple modification to node_after() would fix
that if you were so inclined.

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #3

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

Similar topics

13
9661
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
2
3734
by: Deryck | last post by:
Hi, I am trying to update part of a webpage using javascript. The bit that gets updated will have a variable number of links written to it. I have done this successfully by rewriting the whole page but this seems like overkill (and a maintenance problem too potentially). I thought about defining the area to be updated using a div. Something like this:
8
4313
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to the innerHTML of the form but it fails. ie
10
5397
by: andreister | last post by:
He there! I've discovered that the ================================================= document.links('link_id_here').href = "something"; ================================================= is not applicable for the Firefox (even for the 1.0.6), and I'm falling into passing through the array and checking each link id.
7
2414
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one of the questions, that form is hidden and the next is displayed. Also, as the user answers each question a "count" variable is updated based on their response. I would like the question to show up on the left side and the answer to show up in the...
2
2627
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because the <script> block won't be evaluated. Googling around, a found the createContextualFragment() solution which does execute script code. The following, for example, works:
5
1584
by: Jeremy | last post by:
Does anyone have a clever algorithm for generating an outline of the current document from (client-side) javascript using DOM methods? For example, let's say I predictably have a document structured hierarchically with <h1>...<h6tags. I want to generate an outline of the document wherein I have nested lists of the contents of the headers. Take for example the following snippet of a fictional legal document: ------------ <h1>Main...
7
8969
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses document.write to send output to the browser. This javascript file contains some html code and another script tag. The execution order in Internet Explorer (6&7) appears to be different than that of browsers such as FireFox. Example:
0
10604
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
10356
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...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
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
9179
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...
1
7644
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6874
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
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3006
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.