473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is dynamically creating a new field on a page DHTML, Javascript, XML or a combination?

I want to learn moer of what I saw in a recent example. They create a page
that created new fields/element. It's not like they were hidden and they
displayed them, they were not there, then the script created them.

It used things like parentnode, insertBefore, appendChildNode ,...

Any ideas/direction is appreciated.
Jul 23 '05 #1
6 2947
"NotGiven" <no****@nonegiv en.net> wrote in message
news:V1******** ************@bi gnews1.bellsout h.net...
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they
displayed them, they were not there, then the script created them.

It used things like parentnode, insertBefore, appendChildNode ,...

Any ideas/direction is appreciated.


The answer is Yes!

DHTML (Dynamic Html) is just using Javascript to manipulate
the (html) page dynamically, and the common way to do this,
is to manipulate the pages Document Object Model (DOM)'s
parentnode, insertBefore, appendChildNode , et.c...

Xml is not (usually) used for such things, but with the right
xml style sheet (XSL/XSLT), you can create dynamic HTML-documents
from xml-documents too...

--
Dag.
Jul 23 '05 #2
So if I want to search for web sites to learn more about this typ eof thing,
I would search for DHTML?

"Dag Sunde" <ds@orion.no-way> wrote in message
news:tu******** **********@juli ett.dax.net...
"NotGiven" <no****@nonegiv en.net> wrote in message
news:V1******** ************@bi gnews1.bellsout h.net...
I want to learn moer of what I saw in a recent example. They create a

page
that created new fields/element. It's not like they were hidden and they
displayed them, they were not there, then the script created them.

It used things like parentnode, insertBefore, appendChildNode ,...

Any ideas/direction is appreciated.


The answer is Yes!

DHTML (Dynamic Html) is just using Javascript to manipulate
the (html) page dynamically, and the common way to do this,
is to manipulate the pages Document Object Model (DOM)'s
parentnode, insertBefore, appendChildNode , et.c...

Xml is not (usually) used for such things, but with the right
xml style sheet (XSL/XSLT), you can create dynamic HTML-documents
from xml-documents too...

--
Dag.

Jul 23 '05 #3
"NotGiven" <no****@nonegiv en.net> wrote in message
news:Q6******** ************@bi gnews1.bellsout h.net...
"Dag Sunde" <ds@orion.no-way> wrote in message
news:tu******** **********@juli ett.dax.net...
"NotGiven" <no****@nonegiv en.net> wrote in message
news:V1******** ************@bi gnews1.bellsout h.net...
I want to learn moer of what I saw in a recent example. They create a page
that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the script created them.

It used things like parentnode, insertBefore, appendChildNode ,...

Any ideas/direction is appreciated.


The answer is Yes!

DHTML (Dynamic Html) is just using Javascript to manipulate
the (html) page dynamically, and the common way to do this,
is to manipulate the pages Document Object Model (DOM)'s
parentnode, insertBefore, appendChildNode , et.c...

Xml is not (usually) used for such things, but with the right
xml style sheet (XSL/XSLT), you can create dynamic HTML-documents
from xml-documents too...


So if I want to search for web sites to learn more about this typ eof

thing, I would search for DHTML?


Yes...
....And Javascript, and post specific questions here when you're stuck... ;-)
--
Dag
58°26'15.9" N 008°46'45.5" E
Jul 23 '05 #4
I posted one here a few days ago and no one replied. I thought I might in
the wrong newsgroup. Here's what I posted:

=============== =============== =============

The code below is overwriting itself.

What it is doing is creating the fields correctly the first time through.
Then it writes over those same fields again and again. I can tell because
the value of the first field changes every loop.

Any ideas?

Code:
var ex_counter = 0;
var ex = "";
function ex_morefields() {
var x=document.getE lementById("cho ices");
ex_counter++;
var newfields = document.getEle mentById('ex_fi elds').cloneNod e(true);
newfields.id = '';
newfields.style .display = 'block';
var newfield = newfields.child Nodes;
for (y = 0; y<(x.length); y++) { //loop through all item in the list
ex = x[y].text;
for (var i=0;i<newfield. length;i++) {
var theName = newfield[i].name;
if (theName) {
newfield[i].name = theName;// + ex_counter;
}
if (theName == "exercise") {
newfield[i].setAttribute(' value', ex);
}
}
var insertHere = document.getEle mentById('write _EX');
insertHere.pare ntNode.insertBe fore(newfields, insertHere);
}
} // end add more software script
here's the html in the page:

HTML:
<span id="write_EX"> </span>
Jul 23 '05 #5
On Fri, 17 Sep 2004 14:36:00 -0400, NotGiven <no****@nonegiv en.net> wrote:
I posted one here a few days ago and no one replied.
You posted it yesterday. At a quick glance, I couldn't see what was wrong,
but after reformatting your code, it's quite clear, so in future please
indent code blocks. It's much easier to follow code that way. In addition,
post *all* the relevant HTML. You reference three elements by id, and many
more through the childNodes collection. How can we tell what's being
manipulated without the document?

[snip]
The code below is overwriting itself.
With very good reason. However, you might also like to know that it will
probably fail in most browsers, if you're doing what I think you're doing.
What it is doing is creating the fields correctly the first time through.
Then it writes over those same fields again and again. I can tell because
the value of the first field changes every loop.
That may be so, but you always insert the same node, which results in it
being removed, then being reinserted.
var ex_counter = 0;
var ex = "";
Why is 'ex' global?
function ex_morefields() {
var x=document.getE lementById("cho ices");
ex_counter++;
var newfields = document.getEle mentById('ex_fi elds').cloneNod e(true);
newfields.id = '';
newfields.style .display = 'block';
var newfield = newfields.child Nodes;
for (y = 0; y<(x.length); y++) { //loop through all item in the list
What list?

This is why I said this code will fail. A conforming browser will only
return one node, or nothing at all, with a getElementById call. This means
that the length property will be undefined and the loop will never be
entered. You seem to be under the impression that it will return a
collection which implies a few things:

1) You've only tested on IE, which is far from a compliant browser.
2) You're using the same id on several elements.
3) You haven't validated you page before trying to script it.

The DOM Specification doesn't define specific behaviour with a document
contains elements with identical id attributes and a getElementById call.
This means that only the first element in document order might be
returned. It's even reasonable to assume that null can be returned. What
IE does - return a collection - is certainly not correct as the interface
for the method clearly defines what can be returned, and a NodeList is not
one of the options.

It's advisable to test on a decent browser before checking with IE. You're
more likely to find bugs that way. Opera and Mozilla are good options, and
are available on many platforms. Also validate:
<URL:http://validator.w3.or g/>.
ex = x[y].text;
for (var i=0;i<newfield. length;i++) {
var theName = newfield[i].name;
if (theName) {
newfield[i].name = theName;// + ex_counter;
Rather redundant, isn't it?
}
if (theName == "exercise") {
newfield[i].setAttribute(' value', ex);
Use of setAttribute is usually unnecessary. If the element defines the
attribute as a property, as in the case of INPUT elements and the value
attribute, then

<object>.<prope rty> = <value>;

is all that's required.
}
}
var insertHere = document.getEle mentById('write _EX');
Why do you repeatedly look up this reference?
insertHere.pare ntNode.insertBe fore(newfields, insertHere);
This is the other issue. The newfields variable is only defined once
outside the outer loop, so it never changes. You probably meant
newfield[i], but the first problem is the most pressing as correcting it
might require you to re-examine all of this code, and probably the HTML,
too.
}
} // end add more software script


One final point: In all of the code above, you fail to check if the user
agent supports the methods and objects you use. Always feature test (4.26).

<URL:http://jibbering.com/faq/>

[snip]

I'm sorry if that's a lot of information to throw at you, but it's all
important. If you need more help, you'll have to post your HTML and what
you're trying to accomplish. This would be best done by providing a link
to a demonstration.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
I would like nothing more than to show you the entire page but it is
proprietary at the moment. I'll work on making it more generic then post
it.

Thanks for your expert help. I've been developing for year but in another
language and have little javascript exp other than copying code form
tutorials and maiking it work on my site.

This code is more advanced than I have a prayer of solving at this point.

My goal is to create fields on the fly. This page has a listbox with
several items. I'd like to click a button that will create fields on the
fly that have the listbox items as values in the fields.

What do you suggest I read to learn enough to do this?

Thanks.
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opsehlpsx5 x13kvk@atlantis ...
On Fri, 17 Sep 2004 14:36:00 -0400, NotGiven <no****@nonegiv en.net> wrote:
I posted one here a few days ago and no one replied.


You posted it yesterday. At a quick glance, I couldn't see what was wrong,
but after reformatting your code, it's quite clear, so in future please
indent code blocks. It's much easier to follow code that way. In addition,
post *all* the relevant HTML. You reference three elements by id, and many
more through the childNodes collection. How can we tell what's being
manipulated without the document?

[snip]
The code below is overwriting itself.


With very good reason. However, you might also like to know that it will
probably fail in most browsers, if you're doing what I think you're doing.
What it is doing is creating the fields correctly the first time through.
Then it writes over those same fields again and again. I can tell because
the value of the first field changes every loop.


That may be so, but you always insert the same node, which results in it
being removed, then being reinserted.
var ex_counter = 0;
var ex = "";


Why is 'ex' global?
function ex_morefields() {
var x=document.getE lementById("cho ices");
ex_counter++;
var newfields = document.getEle mentById('ex_fi elds').cloneNod e(true);
newfields.id = '';
newfields.style .display = 'block';
var newfield = newfields.child Nodes;
for (y = 0; y<(x.length); y++) { //loop through all item in the list


What list?

This is why I said this code will fail. A conforming browser will only
return one node, or nothing at all, with a getElementById call. This means
that the length property will be undefined and the loop will never be
entered. You seem to be under the impression that it will return a
collection which implies a few things:

1) You've only tested on IE, which is far from a compliant browser.
2) You're using the same id on several elements.
3) You haven't validated you page before trying to script it.

The DOM Specification doesn't define specific behaviour with a document
contains elements with identical id attributes and a getElementById call.
This means that only the first element in document order might be
returned. It's even reasonable to assume that null can be returned. What
IE does - return a collection - is certainly not correct as the interface
for the method clearly defines what can be returned, and a NodeList is not
one of the options.

It's advisable to test on a decent browser before checking with IE. You're
more likely to find bugs that way. Opera and Mozilla are good options, and
are available on many platforms. Also validate:
<URL:http://validator.w3.or g/>.
ex = x[y].text;
for (var i=0;i<newfield. length;i++) {
var theName = newfield[i].name;
if (theName) {
newfield[i].name = theName;// + ex_counter;


Rather redundant, isn't it?
}
if (theName == "exercise") {
newfield[i].setAttribute(' value', ex);


Use of setAttribute is usually unnecessary. If the element defines the
attribute as a property, as in the case of INPUT elements and the value
attribute, then

<object>.<prope rty> = <value>;

is all that's required.
}
}
var insertHere = document.getEle mentById('write _EX');


Why do you repeatedly look up this reference?
insertHere.pare ntNode.insertBe fore(newfields, insertHere);


This is the other issue. The newfields variable is only defined once
outside the outer loop, so it never changes. You probably meant
newfield[i], but the first problem is the most pressing as correcting it
might require you to re-examine all of this code, and probably the HTML,
too.
}
} // end add more software script


One final point: In all of the code above, you fail to check if the user
agent supports the methods and objects you use. Always feature test
(4.26).

<URL:http://jibbering.com/faq/>

[snip]

I'm sorry if that's a lot of information to throw at you, but it's all
important. If you need more help, you'll have to post your HTML and what
you're trying to accomplish. This would be best done by providing a link
to a demonstration.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #7

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

Similar topics

4
3695
by: Gurry | last post by:
Hi there I would like to write a javascript function that creates a drop-down list dynamically. I read on the docs that most HTML controls can not be created on run-time. what kind of work-arounds do you use in this case? maybe DHTML? do you have any example ? Javascript allows you to create the options of the drop-down list dynamically but not the drop-down list itself, I believe. Actually the same question goes for any other HTML...
3
1726
by: The Pritchard | last post by:
I want the user to be able to save the information displayed on a dynamically created page. When I write a script like the following: <SCRIPT> winNew = window.open("","test"); winNew.document.writeln("Hello World!"); winNew.document.close(); winNew.focus();
3
1761
by: ojvm | last post by:
thanks in advance for reading this. i am a really ignorant about js, so i need a guru to help me. i need to add n number of text box in a html page, the main idea is when the user press a button apear 2 text box and if he do it again apear 2 text box more and so on, also need that all the text boxes has a unique id, in order to make some thing whit the values. but i dont know how to do it. please hel me i'm trapped in this.
1
1772
by: eddie wang | last post by:
How to move around a picture file dynamically in an asp page? Any link to sample code will be great. Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
5731
by: Quentin | last post by:
Hey there ! I made my own WebControl, that inherits from WebControls, and i added an HtmlTable to it. I would like to include a file, dynamically, to one of its cells... I've already searched, and found HttpContext.Current.Server.Execute("mapage.aspx") but it executes the page where i call it, and not in the cell... i also tried something like that : MyTable.Rows(0).Cell(0).InnerHtml = Server.Execute("MaPage.aspx") but it doesn't...
4
2241
by: Jaime Stuardo | last post by:
Hi all... I need to add some JavaScript code that is dynamically generated to some point of the page. Currently I'm using ClientScript.RegisterStartupScript(GetType(), "menu", "<script type=\"text/javascript\">" + oMenu.BuildMenu(true, true, true) + "</script>"); But the script is added to the end of the page, but I need it to be added at
5
2096
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script rather than using the html <form> and related tags. Can this be done to support both IE, Firefox? Any code snippets or samples showing how to do this would be fantastic. Thanks! --- Mike
6
6646
by: Amit Maheshwari | last post by:
I have my aspx page on which i am creating <input type=text> on client side using javascript. Now when i submit my page i need to access these controls to get the value entered by the user. the code is like <script language="javascript"> <!-- //to count no of file upload controls var intRowCount = 2; function AddApp()
4
4490
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new row to the table, updates all of the child control Ids and sets visibility etc. The hidden...
0
8788
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
9476
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
9335
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
9263
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
9208
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
8210
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
6053
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
4570
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...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.