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

Clearing it out

Cy
I have a script that uses the DOM to draw to the page depending on a
selection by the user. Problem is that if they hit the selection
again it draws the info again creating more than one instance of what
should actually be on screen.

In addition, if the user selects one thing, then realizes they want
another the old info is not erased. Instead the new info is appended
to what was there before.

How do I keep from having the same info drawn over and over, and how
can I replace the info if the user makes a wrong selection?

Below is the code I am using. A div called "new_page_toggle" is given
the result.

// New page or not function
function new_page(decision) {
document.getElementById('new_page_toggle').vlue = "";
if (decision == 'yes') {
br_tag1 = document.createElement('br');
br_tag2 = document.createElement('br');
br_tag3 = document.createElement('br');

title_text = document.createTextNode("Enter the title text to
be displayed in the browser");
bold_tag1 = document.createElement("B");
bold_tag1.appendChild(title_text);
title_input = document.createElement('input');
title_input.setAttribute("type", 'text');
title_input.setAttribute("name", 'browser_title');
title_input.setAttribute("id", 'browser_title');
title_input.setAttribute("size", '127');

disc_text = document.createTextNode("Enter the text to be
displayed when found by internal search engine");
bold_tag2 = document.createElement("B");
bold_tag2.appendChild(disc_text);
disc_input = document.createElement('input');
disc_input.setAttribute("type", 'text');
disc_input.setAttribute("name", 'search_desc');
disc_input.setAttribute("id", 'search_desc');
disc_input.setAttribute("size", '127');
document.getElementById('new_page_toggle').appendC hild(bold_tag1);

document.getElementById('new_page_toggle').appendC hild(br_tag1);

document.getElementById('new_page_toggle').appendC hild(title_input);

document.getElementById('new_page_toggle').appendC hild(br_tag2);
document.getElementById('new_page_toggle').appendC hild(bold_tag2);

document.getElementById('new_page_toggle').appendC hild(br_tag3);

document.getElementById('new_page_toggle').appendC hild(disc_input);

} else if (decision == 'no') {
br_tag1 = document.createElement('br');

url_text = document.createTextNode("Enter URL(s) of the
page(s) to edit");

document.getElementById('new_page_toggle').appendC hild(url_text);

document.getElementById('new_page_toggle').appendC hild(br_tag1);
for (i=1; i<=5; i++) {
url_input = document.createElement('input');
url_input.setAttribute("type", 'text');
url_input.setAttribute("name", 'url_'+i);
url_input.setAttribute("id", 'url_'+i);
url_input.setAttribute("size", '127');

bold_tag = document.createElement("B");
num = document.createTextNode(i+")-");
bold_tag.appendChild(num);

br_tag2 = document.createElement('br');

document.getElementById('new_page_toggle').appendC hild(bold_tag);

document.getElementById('new_page_toggle').appendC hild(url_input);

document.getElementById('new_page_toggle').appendC hild(br_tag2);
}
}
}
Jul 23 '05 #1
5 1549
Ivo
"Cy" wrote
I have a script that uses the DOM to draw to the page depending on a
selection by the user. Problem is that if they hit the selection
again it draws the info again creating more than one instance of what
should actually be on screen.
(...) Below is the code I am using. A div called "new_page_toggle" is
given the result.


Remove the div from the DOM and re-create it:
var oldpagetoggle = document.getElementById('new_page_toggle');
if(oldpagetoggle) document.body.removeNode(oldpagetoggle);
var newpagetoggle=document.createElement('div');
newpagetoggle.id='new_page_toggle';
document.body.appendChild(newpagetoggle);

HTH
Ivo
Jul 23 '05 #2
"Cy" <cy******@sas.com> wrote in message
news:be********************************@4ax.com...
I have a script that uses the DOM to draw to the page depending on a
selection by the user. Problem is that if they hit the selection
again it draws the info again creating more than one instance of what
should actually be on screen.

In addition, if the user selects one thing, then realizes they want
another the old info is not erased. Instead the new info is appended
to what was there before.

How do I keep from having the same info drawn over and over, and how
can I replace the info if the user makes a wrong selection?

Below is the code I am using. A div called "new_page_toggle" is given
the result.

// New page or not function
function new_page(decision) {
document.getElementById('new_page_toggle').vlue = "";
if (decision == 'yes') {
br_tag1 = document.createElement('br');
br_tag2 = document.createElement('br');
br_tag3 = document.createElement('br');

title_text = document.createTextNode("Enter the title text to
be displayed in the browser");
bold_tag1 = document.createElement("B");
bold_tag1.appendChild(title_text);
title_input = document.createElement('input');
title_input.setAttribute("type", 'text');
title_input.setAttribute("name", 'browser_title');
title_input.setAttribute("id", 'browser_title');
title_input.setAttribute("size", '127');

disc_text = document.createTextNode("Enter the text to be
displayed when found by internal search engine");
bold_tag2 = document.createElement("B");
bold_tag2.appendChild(disc_text);
disc_input = document.createElement('input');
disc_input.setAttribute("type", 'text');
disc_input.setAttribute("name", 'search_desc');
disc_input.setAttribute("id", 'search_desc');
disc_input.setAttribute("size", '127');
document.getElementById('new_page_toggle').appendC hild(bold_tag1);

document.getElementById('new_page_toggle').appendC hild(br_tag1);

document.getElementById('new_page_toggle').appendC hild(title_input);

document.getElementById('new_page_toggle').appendC hild(br_tag2);
document.getElementById('new_page_toggle').appendC hild(bold_tag2);

document.getElementById('new_page_toggle').appendC hild(br_tag3);

document.getElementById('new_page_toggle').appendC hild(disc_input);

} else if (decision == 'no') {
br_tag1 = document.createElement('br');

url_text = document.createTextNode("Enter URL(s) of the
page(s) to edit");

document.getElementById('new_page_toggle').appendC hild(url_text);

document.getElementById('new_page_toggle').appendC hild(br_tag1);
for (i=1; i<=5; i++) {
url_input = document.createElement('input');
url_input.setAttribute("type", 'text');
url_input.setAttribute("name", 'url_'+i);
url_input.setAttribute("id", 'url_'+i);
url_input.setAttribute("size", '127');

bold_tag = document.createElement("B");
num = document.createTextNode(i+")-");
bold_tag.appendChild(num);

br_tag2 = document.createElement('br');

document.getElementById('new_page_toggle').appendC hild(bold_tag);

document.getElementById('new_page_toggle').appendC hild(url_input);

document.getElementById('new_page_toggle').appendC hild(br_tag2);
}
}
}

Replace
document.getElementById('new_page_toggle').value = "";

with
document.getElementById('new_page_toggle').innerHT ML = "";
Jul 23 '05 #3
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:S6Rvc.4617$%F2.3026@attbi_s04...
<snip>
Replace
document.getElementById('new_page_toggle').value = "";

with
document.getElementById('new_page_toggle').innerHT ML = "";


I would have thought that in a script that already extensively uses DOM
Level 2 Node manipulation methods the expected method of removing all of
the contents from a DIV would be:-

var divElement = document.getElementById('new_page_toggle');
var divChildren = divElement.childNodes;
for(var c = divChildren.length;c--;){
divElement.removeChild(divChildren[c]);
}

- (or one of the many variations on that theme).

Richard.
Jul 23 '05 #4
"Richard Cornford" <ri*****@litotes.demon.co.uk> wrote in message
news:c9**********@titan.btinternet.com...
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:S6Rvc.4617$%F2.3026@attbi_s04...
<snip>
Replace
document.getElementById('new_page_toggle').value = "";

with
document.getElementById('new_page_toggle').innerHT ML = "";


I would have thought that in a script that already extensively uses DOM
Level 2 Node manipulation methods the expected method of removing all of
the contents from a DIV would be:-

var divElement = document.getElementById('new_page_toggle');
var divChildren = divElement.childNodes;
for(var c = divChildren.length;c--;){
divElement.removeChild(divChildren[c]);
}

- (or one of the many variations on that theme).

Richard.

I'm sure you're right about using a "DOM Level 2 Node manipulation methods"
approach.

I just found something that worked and passed it on.

I tried the solution offered by "Ivo" but it failed on:

document.body.appendChild(newpagetoggle);

Jul 23 '05 #5
"McKirahan" wrote:
<snip>
I tried the solution offered by "Ivo" but it failed on:

document.body.appendChild(newpagetoggle);


Did it? I would have expected:-

| if(oldpagetoggle) document.body.removeNode(oldpagetoggle);

- to have been a problem as - removeNode - is not a DOM Core method (I
think it is a Microsoft extension). But his code also makes the
assumption that the DIV in question is a direct child of the body.

Richard.
Jul 23 '05 #6

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

Similar topics

18
by: Niels | last post by:
Hi group, I have some problems with clearing floated divs. My usual method works fine in Konqueror, but not in Firefox. Here's an example: <html><body> <div id='left' style='float:left;...
0
by: Gary | last post by:
I have a problem with the datagrid not clearing when the datasource changes, a few fields remain on the screen and even when new data would fill those grid squares the old data remains. I wind...
4
by: Roubles | last post by:
Hi All, Quick question; what is the difference between initializing and clearing a structure like this: mystruct_t a = {0}; and initializing and clearing it like this:
1
by: raghavendra | last post by:
Hi, i am facing problem clearing screen in console application. As, in C++ we have clrscr(); Is? their any similar type of function is avaliable.. Raghavendra...
9
by: Werner Hempel | last post by:
Hello, I'm trying to do a simple three column layout, with two divs (#left and #right) floating left and right, and the #content-div with margins in between, and all three in a wrapper-div. The...
65
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the...
0
by: negmat | last post by:
Hello everyone, I have the following question: I am aware that the objects currently in the cache can be viewed by issuing the following command: SELECT * FROM master.dbo.Syscacheobjects ...
65
by: Leslie Kis-Adam | last post by:
Hi everyone! Does anyone know, if it is possible to clear the screen in ANSI C? If it is,then how? Any help would be appreciated. Laszlo Kis-Adam <dfighter_AT-NOSPAM_freemail.hu
12
by: Avalon1178 | last post by:
Hi, I have an application that periodically uses a std::string variable which is assigned a VERY VERY large string (15000000+ bytes long). This application is essentially a daemon, and it polls...
1
by: Vayse | last post by:
I have a databound form, frmClients. One of the field is a combo box, comDepartment, which lets a user select a department for the Client. But I can't figure out how to clear the box. That is,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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,...

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.