473,795 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically building layers?

Not really sure how to ask this. I'm new to CSS/DHTML

I want to create something similar to how yahoo and gmail handle the
"to" field when you type an email.

If you start typing "d" you will see a list of all the the people in
your address book whos last names start with "d". Type another letter
"e" for example and the list is narrowed to people who's names start
with "de". etc etc.

I'm experience enough with javascript that I'm able to create an array
and resize it based on what you've typed, ie, I've got an array that I
can resize to just have my people with "de" in the name.

It's the next step that has me stuck. How do I create the new layer and
dynamically populate it with the contents of my array?

(Step 2 will be how do I tell when someone has clicked on text in this
new layer.)

Is anyone aware of any web page that shows you how to do something like
this?

Thanks.

Sep 30 '05 #1
1 1735


engwar wrote:

It's the next step that has me stuck. How do I create the new layer and
dynamically populate it with the contents of my array?


If you know the HTML structure you want to build (HTML does not know
layers but it has elements like <div> elements and then CSS can be
applied to those elements to stack them if needed (position and z-index
CSS properties) then you simply need to learn the W3C DOM where in a
HTML document you can create any element if you know its tag name as
follows:
var element = document.create Element('tagnam e')
e.g. for a <div> element object you do
var div = document.create Element('div');

Now within the HTML DOM you can script most HTML attributes of the HTML
element as properties of the script object created so you can do
div.id = 'layer1';
// class attribute is scripted as className property
div.className = 'css-class-name-here';

If you want to script the CSS inline style of an element object then you
can set and read
div.style.cssPr opertyName
e.g.
div.style.posit ion = 'absolute';
div.style.zInde x = '10';
div.style.left = '100px';
div.style.top = '200px';

To fill an element with content you simply create other nodes (e.g.
elements and text nodes) as needed and use DOM methods like appendChild
or insertBefore to put one node into the other e.g.
var p = document.create Element('p');
p.appendChild(d ocument.createT extNode('Kibolo gy for all.'));
// insert into div created earlier
div.appendChild (p);

Now you have a complete <div> element object with CSS inline style and
with content created and all you need to do to have it show up is insert
it into some other node already in the document e.g. in the document
body as the easiest approach
document.body.a ppendChild(div) ;
So there is nothing special nowadays to create layers, the DOM allows to
use the same approach to create any HTML element there is as an object,
set its attributes as properties and insert content by creating contents
as nodes as well and inserting them into some container element.

You can do that with IE 5 and later, Netscape 6 and later, Opera 7 and
later, and other modern browsers around like Safari or Konqueror.

Granted, in reality there are some issues with the general approach
working flawlessly where implementations are not complete or build on
legacy stuff but it surely helps to understand and use that approach
first and then look for the issues with one browser or the other for
certain elements or attributes.
The DOM inspector of Mozilla or Firefox is a nice tool to learn about
the DOM by simply loading a static HTML document and see how this
translates into the DOM tree object model with the document node having
anything else as child nodes or descendant nodes, with the root element
(the <html> element in HTML) being a child node of the document node and
that root element containing all other elements as child or descendant
nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 1 '05 #2

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

Similar topics

10
9136
by: TheKeith | last post by:
I don't know much about javascript, so take it easy on me. Is there a way to dynamically change a CSS layers dimensions on the fly. Here is what I'm doing. I have a bunch of thumbnails that when clicked on, will open up the full view in a CSS layer, as opposed to a pop-up window let's say. I had this before, but with one layer for each image, and as you might imagine, the markup was way too bloated. So can I just change the css layers...
8
11098
by: Freek te Water | last post by:
Hi, Hope no-one is offended by my probably noob question... Context: I have a web page design, which always centres in the middle of the screen (using a 100%*100% HTML-table). Now I also use layers, that get visible when something is clicked. All works fine. Problem:
27
4754
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second box, I concatenate the selections from the two boxes and add the string to a list at the top of the form, using createElement and appendChild. The list is actually a bunch of span elements contained within a div. Each span element includes a small...
17
2077
by: Nick | last post by:
I am doing some research into building web applications using Object Oriented techniques. I have found the excellent patterns section on the MSDN site, but other than that I cannot find any good, concrete examples. I know Microsoft are really pushing OO with the .NET Framework and C#, but for web stuff I am finding good examples sparse. Can anyone offer some links to articles, whitepapers, sites etc that maybe give a good overview of the...
5
1301
by: Jason | last post by:
Hi all I am building a page dynamically on Page_Load. using Table web controls for this. the web page builds up and loads up and displays ok. but as soon as there is a post back of any sort, all my dynamic building is gone. the page reverts back to it's "original" design time state. i have a OK button, that when the user clicks on this button, it will go and get data from the dynamically built page. but obviously i cant do that,
0
1069
by: Craig G | last post by:
i want to build a datagrid to use as a register for a number of courses. what i want to happen is that the tutor selects the course from a combo box. this then builds a grid for all students enrolled on the course along with the number of weeks the course has to run i want the datagrid to build a column for each week of the course. and then list the students in rows. with a checkbox being in every itemtemplate so that the tutor can say...
7
10067
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the main menu instead of showing all possible options and only enabling/disabling certain ones. I have a table that stores the menu item name, parent item (if applicable), display order, etc. so that I can dynamically load my
2
1804
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder. Using buttons for loading new content works fine. But i still want to use a function which is callable per javascript. I think this way is more flexable than using the Buttons, becaus every button needs it's own Sub-Routine. But i want to have...
8
2821
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. How can I get the height of the control (in code) after it grows? I am building a windows form dynamically, creating controls and placing them on the form. There can be dozens of controls of all types on the form. This is for dynamic...
0
9519
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
10438
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
10001
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
9042
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
7540
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
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.