R
E
S
O
U
R
C
E
S
       Question Index      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: side or top popup menus, buttons, image rotators, navbars, tons more.
_______________________

Send us your questions and wittiest comments.
_______________________

Report errors on our site.
_______________________

Share your neatest DHTML examples with us; we may publish them.
_______________________


_______________________

      QUESTION INDEX      

Question Index
Browser Insanity
JavaScript
Animation
Buttons and Menus
CSS and HTML
PHP
Personal Status Boards
Content Management
   Systems
Website Directory
   CMS Systems


 INFORMATIVE ARTICLES 

Menus-and-Buttons-
Part-I.htm


Menus-and-Buttons-
Part-II.htm


Change-Div-Size-Color-
and-Location-with-the-
W3C-DOM.htm


Bouncing-Ball-Animation-
with-the-W3C-DOM.htm


Style-Changes-with-the-
W3C-DOM.htm


Animation-with-the-
W3C-DOM.htm


Window-Play-and-Some-
Important-DOM-Methods.htm


Using-getElementsByTagName
-and-getElementsByName.htm


The-CSS-Resources-Intro-
Page.htm


Convert-Word-Files-to-HTML-
and-Install-Editor2-to-
Use-Instead-of-NotePad.htm


CSS-Issues.htm

What Are Fifteen Simple Methods of Doing Web-Page Pop-ups?

Security levels from Javascript and PHP input filtering

What is a regular expression general input validator?

What is a regular expression user name validator?

What is a regular expression password validator?

What is a regular expression email validator?

What is a regular expression URL validator?

How can I convert a Javascript array to a PHP array?

How can I Dynamically Create Input Boxes with Validation?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do I add html to a web page with JavaScript, PHP or ssi includes?

How do I add html to a web page with JavaScript includes?


PHP

How do you put PHP variables in URL and link text?

What is PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts with a captcha?

What is Administrator PHP Code for Multiple PSB Hosts?

What's the PHP code for a script for a PSB?

What's the PHP code for a script for PSB updating?

What's the PHP code for a script if you forgot your user name?

What's the PHP code for a script if you forgot your password?

What's the PHP code for a script to change a member's email address?

What's the PHP code for a script to connect to a MySQL database?

What's the PHP code for a script to close a member's account?

What's the PHP code for a script to edit group member?

What's the PHP code for a script to add group member?

What's the PHP code for a script to reset a MySQL table's data to its original?

What's the PHP code for a script to edit a MySQL table's data?

What's the PHP code for a script to change a username?

What's the PHP code for a script to change a password?

What's the PHP code for a script to delete group member?

What's the PHP code for a script to view membership data?

What's the PHP code for a script to change an administrator's password?

What's the PHP code for a script to logout?

What's the PHP code for a script to login?

Security levels from Javascript and PHP input filtering

Security levels and PHP

How can I convert a Javascript array to a PHP array?

What is PHP Code to Prevent Duplicate Data Input - Like User Names or Members?

What is PHP Code for PSB Status Update for Multiple PSB Hosts?

How do I sort 1 PHP array and have the other arrays sort in parallel to how the first array sorts?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do you do PHP-to-JavaScript String Conversion with No JSON?

How do you Convert PHP String to JavaScript String?

How do you Post a JavaScript Array to a PHP Array?

How do you send a value to PHP using JavaScript?

Info on unwanted primary field auto-sorting

How can I do instant article font size, font family, and paragraph formatting with radio buttons?

How can I create custom HTML tags that are safer for MySQL databases?

How can I edit text from MySQL databases by using a textarea box?

How can I highlight matched search terms in a MySQL database table search?

How can I search using not only exact phrase matching but also a series of words to match in a MySQL database table search?

What's the code for an Ajax and PHP Based Input Filter?

Ajax and PHP Based Insult Auto-Completer

How can I use PHP and MySQL for Checking Key Codes to Allow Update to a New Software App Version?




Personal Status Boards (PSB™)

Standard Free PSB

PSB Pro Version

Social PSB

Social PSB Plus (with Email)

Business PSB

Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement




Article Content Management System

Content Management System Introduction

Content Management System—Article Navigation

Content Management System—Article Indexing

Content Management System—Article Editing

Content Management System—Article Searching

Content Management System—Article Deleting

Content Management System—Article Writing

Content Management System—Article Reading

What are the terms of use for our Article Content Management System?




Website Directory Content Management System

Website Directory—Delete Category

Website Directory—Delete URL

Website Directory—Add URL

Website Directory—Add Category

Website Directory—Directory Creating

Website Directory—View by Category (Demo Code)

Website Directory—View by URL (Demo Code)

Website Directory—View by Category (Demo)

Website Directory—View by URL (Demo)

Website Directory—View

Website Directory—View (Demo)



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Window Play and Some Important DOM Methods

The getdivelementsfourways-w3cdom.html file looks at many document object methods that relate to dynamic web page alterations. The file also deals with windows and alert dialog box usage, with opening and closing windows as well as writing to them and putting images and even animated gifs in them.

The four main methods of changing document element property styles using the DOM are getElementById(), getElementsByName(), getElementsByTagName(), and changing an element’s class name (we do it two ways in this file) to alter its style property values.

A fifth way relates only to DOM arrays. There are five document object arrays which can be addressed: images, applets, links, forms, and anchors. We change all image source values in the document at once in our byimagearray() function. We don’t consider this one of the four main methods of changing document elements, since how often will you need to replace all the image sources on a page at once? (That’s quite a rollover!) And if you only want to change some of them, how will you know which are which? Image array numbers aren't that helpful. Also, one of the other four ways of changing document element property styles is bound to be better than this. Node-based JavaScript routines are even worse, for most normal website creation purposes, however much they may be fun to fool with.

There are open(), close(), write(), writeln() document object methods in addition to the document object methods getElementById(), getElementsByName(), and getElementsByTagName(). We’ll be exploring them all here.

First, let’s look at the byclass() function, which is one of our two class changing functions. Note the f flag, which alternates between 0 and 1 every other time the first image is clicked. It moderates the resizing of all five images at once from class c to class d alternately. The relevant CSS style rules from the styling section are shown below the function. This function happens to be set up to alternate the class name value for all images whose id is from n1 to n5. The idletter value sent to the function as a parameter is n and the value of i in the for loop is allowed to increment to 5 but no higher. When you concatenate the two together and make it a string you get from n1 to n5. Only one element can have a certain id, so the getElementById() method is best at changing one particular element at a time. But if you want all the classes changed on many elements at once that don’t necessarily have the same tags or names, a range of id names will do it. The reason this entire function is so powerful is that you can pick and choose some but not all of a certain type of element and choose to change from one to dozens of its style property values all at once without knowing any document object array numbers. We could have combined name and class rather than id and class and got an equally powerful function—it depends on your needs.

A warning is in order about using class changing functions. If they're the only type of element changing functions you'll be using, then there's nothing to be concerned about. But if you'll be mixing other methods with class changing ones, be aware that in some cases class changes won't work if you’ve used other methods first. It’s why our class changing function byclass() is first. Try out this getdivelementsfourways-w3cdom.html file and you'll soon learn that even though if you click the first image several times it will change all images alternately bigger and smaller like it’s programmed to do, the minute you click any of the other images, the first image will be unresponsive from then on. This is because of the specificity aspect of the CSS cascade rules which say class is less specific than id so it loses any contest.

function byclass(idletter,classofnextwidth){ if(!f){f=1}else{f=0;classofnextwidth="c";}

for(var i=1;i<6;i++){q=(idletter + i).toString();

var e=document.getElementById(q);

e.className = classofnextwidth;}

}

.c {width:72px;}

.d {width:100px;}

Here's the other class changing function, and if there were id-based span tag changers in the page code, they would win any contests with this function because of what we've already discussed. It changes all span tags alternately between classes u and v, which takes the word "bottom" (the only word between span tags) and changes it between black and red—sort of like when a young would-be rapper’s mother catches him using the "b" word to refer to women. We know, don’t quit our day jobs. This function changes all tags of a type to a new class. The CSS style rules are given below the function. Its comprehensiveness powers are obvious, but it might often be overkill in that it would be too comprehensive.

function byclassintag(thetag, thenewclassvalue) {if(!h){h=1}else{h=0;thenewclassvalue='u';}

var e=document.getElementsByTagName(thetag);

for(var i=0;i<e.length;i++){e[i].className = thenewclassvalue;}

}

.u {color:black;}

.v {color:red;}

The getElementById() method is the most-used DOM method. If you dump the second line of the function, you'd see its normal configuration. But here it’s being used to change one style property value of all the elements with ids of n1 to n5. One would, in practice, be more likely to use the name attribute on a selection of elements and change them all—like the function below byid()—than make the getElementById() method do it. But for our demonstration purposes, we wanted you to see how the five page images could use any of five methods to change all of them at once.

function byid(idletter,nextwidth){

for(var i=1;i<6;i++){q=(idletter + i).toString();

var e=document.getElementById(q);

e.style.width=nextwidth;}

}

The byname() function is perfect for changing a style property value on a selection of elements that aren't necessarily all of one HTML tag type or all of the elements that have a certain HTML tag. No, we didn’t just repeat ourselves—read it again. Here the elements with a certain name are all to be found in a convenient array so you can deal with them en masse.

function byname(thename,nextwidth){

var e=document.getElementsByName(thename);

for(var i=0;i<e.length;i++){e[i].style.width = nextwidth;}

}

The bytag() function is perfect for any time you wish to change property style values of all the tags of one type, such as <img>, <div>, <p>, <input>, <span>, etc. The elements with one tag type are found in an array so a simple for loop can process them efficiently.

function bytag(thetag,nextwidth){

var e=document.getElementsByTagName(thetag);

for(var i=0;i<e.length;i++){e[i].style.width = nextwidth;}

}

A less common method of getting at all the images in a document is to use the image array—one of the five document object arrays. Here the source image for all the page’s images is switched, and the g flag assures that the n101.jpg image alternates with the n116.jpg image when the button gets depressed.

function byimagearray(newimage){if(!g){g=1}else{g=0;newimage='n101.jpg';}

var e=document.getElementsByTagName("img");

for(var i=0;i<e.length;i++){document.images[i].src = newimage;}

}

Next we have the divs with the pictures of website buttons in them. They all have class b (the class b CSS rules are at the conclusion of the divs below). They're wide to accommodate the text next to the buttons. The one inline style we felt appropriate for this demonstration is the one that gives the vertical position of each div. Class b covers the other necessities. The divs have onClick event handlers that activate the images, running the various functions and passing the needed parameters. Note that all the images have name, id, src, and class attributes that the functions use to deal with the whole set of images.

<div class="b" style="top:40px;" onClick="javascript:byclass('n','d')"><img src="n101.jpg" id="n1" name="n" class="c"><b>&nbsp;&nbsp;click for change by class</b></div>

<div class="b" style="top:110px;" onClick="javascript:byid('n','120px')"><img src="n101.jpg" id="n2" name="n" class="c"><b>&nbsp;&nbsp;click for change by id</b></div>

<div class="b" style="top:180px;" onClick="javascript:byname('n','140px')"><img src="n101.jpg" id="n3" name="n" class="c"><b>&nbsp;&nbsp;click for change by name</b></div>

<div class="b" style="top:250px;" onClick="javascript:bytag('img','160px')"><img src="n101.jpg" id="n4" name="n" class="c"><b>&nbsp;&nbsp;click for change by tag</b></div>

<div class="b" style="top:320px;" onClick="javascript:byimagearray('n116.jpg')"><img src="n101.jpg" id="n5" name="n" class="c"><b>&nbsp;&nbsp;click for change by image array</b></div>

.b {position:absolute; height:28px; width:400px; left:200px;}

And now we’ll consider the other common way to activate functions besides graphics links: text links. The word javascript tells the link to find its target in the JavaScript functions, not on some other HTML page or an anchor on this page. Note the span tag with its class u which we've already discussed above—the text color of the word BOTTOM alternates. The link that runs the span tag is next. The next two links open and close a window with an image in it. The next two links open and close a window with a bit of text followed by an animated gif. If you click the link in IE, the window moves. But in Nutscape 7, it loads the big window’s content into the little window; this is a serious browser bug, so if any of you out there can figure out a work-around, contact us ASAP. The next two links open and close a window with for-loop-generated text followed by an image of a blank popup menu.

<P>CLICK FROM TOP TO <span class="u">BOTTOM</span>, ONCE EACH</P>

<a HREF="javascript:byclassintag('span', 'v')">change BOTTOM</a><br>

<a HREF="javascript:pictureWindow()">open picture window</a><br>

<a HREF="javascript:shutWindow()">close picture window</a><br>

<a HREF="javascript:createWindow()">open tiny window</a><br>

<a HREF="javascript:dumpWindow()">close tiny window</a><br>

<a HREF="javascript:openWindow()">open window</a><br>

<a HREF="javascript:closeWindow()">close window</a><br>

The next two links open alert dialog boxes. The first is small and the second one shows that you can display a huge amount of material in such a box if you want to. But both boxes illustrate the fact that the alert box is a great tool for 1001 uses.

If you're debugging and want to find out what your JavaScript variable values are at a certain place in your code, this is a way to stop the action and peruse the values. You simply use code like alert(x + ":" + y + ":" + z); to see your x, y, and z values. Or if you need to see how the values change and you don’t know when a weird change is occurring, either use a step-through debugger or the status bar. Tracking values there means you can see them change as it happens. Use code like window.status= x + ":" + y + ":" + z; or if you actually think you might be enough of a hair-brain to forget what you're tracking, use window.status= "x:" + x + ", y:" + y + ", z:" + z;. If you use the document.write() method in debugging, you'll have to hit the back button to get back to the page you were testing. We prefer the status bar and alert box strategies.

<a HREF="javascript:alerted()">alert box</a><br>

<a HREF="javascript:alerting()">bigger alert box</a><br><br>

This link starts writing a new document, so it isn't that hot a tool for changing text on a the page you're on, dynamically, without leaving the page. But, not to worry, you can use obj=document.getElementById(q); obj.innerHTML= "here's the replacement text"; anytime you need to mess with your current web page’s text on the fly. You don’t need document.write() for that!

<a HREF="javascript:documentwrite()">document writing</a><br>(press the back<br>button once you<br>leave here . . .)

After a quick browser sniff—since later we will need to know if Microsoft or Nutscape is to blame for the browser, here are the functions that perform all the wonders we just got through discussing:

var Netscape=(navigator.appName.indexOf("Netscape") != -1);

Note that we give the URL of the window contents here in the first parameter instead of an empty string since we want a specific image in window object w. The second parameter, ww, is just a name we can use to reference window object w in link or something. And the third parameter is just a sequence of window parameters that must not have any spaces in it:

function pictureWindow(){w=window.open("circuitboard-smallblue.jpg","ww","top=117,left=540,width=170,height=132");}

Here we close window w and avoid errors by making sure it exists and isn't already closed:

function shutWindow(){if(w && !w.closed) w.close();}

The next function is IE only, although we don’t know anything about Nutscape that should prevent a moveTo() window method from working like it should rather than abandoning its contents and opting to jam the big window’s contents into itself. I smell B-U-G! If any of you geniuses out there discover a work-around, tell us, and if the solution is simple and obvious, please don’t use the word "dumb" in your reply! Everyone is entitled to a brain fart occasionally without teasing! So the question then becomes: Is it our brain fart or Nutscape’s? and why does it work great in IE? Don’t forget to remove the ! before Netscape for testing your fix on Nutscape.

function createWindow(){if (!Netscape) { var aa="<html><head><\/head><body><p>imagine all the great stuff you can stick in here<\/p><a HREF=\'#\' onClick=\'javascript:moveTo(644,344);\'><img src=\'anim3.gif\' width=\'72\' height=\'28\'><\/a><\/body><\/html>"; r = window.open("","rr","top=117,left=540,width=100,height=160");

r.document.write(aa);r.document.close();}

else

{alert("the moveTo will mess up on Netscape; contact us if you know why!");}}

function dumpWindow(){if(r && !r.closed) r.close();}

As you can see when you test functions like the following, both IE and Netscape can use the document.write() method to create windows on the fly, with both text and images in them, without bombing, doing weird things, or every voting for Bush again (actually, that in and of itself qualifies as a weird thing so we were redundant there). Observe that the writeln() method is used because the <br> won't do much without a carriage return in such a situation, and that’s what this method does.

function openWindow(){newWindow = window.open("","w","top=117,left=540,width=220,height=400");

newWindow.document.write("<html><head><\/head><body><p>here comes some junk<\/p>");

for(i=0;i<11;i++){newWindow.document.writeln("loop is at number " + i + "<br>");}

newWindow.document.write("<br><img src='r14.gif' width='88' height='115'><\/body><\/html>")

newWindow.document.close();}

function closeWindow(){if(newWindow && !newWindow.closed) newWindow.close();}

This alert box argument merely states the obvious: countless uses for message delivering to website visitors or JavaScript programmers are possible with this simple tool. The \n is an "escaped" new line command. Escaped means put in a backslash so the following character will not be wrongly interpreted.

function alerted(){alert("variable without quotes or\n message in quotes");}

This nutty alert box in no way proves we were high when we wrote the code. Nor does it prove we weren't! The numbers one gets when one leaves randomly generated numbers the way they are, rather than using the Math.floor() or parseInt() methods on them, have 12 decimal places. So alert() methods can have thousands of characters worth of data in them, enough for a lengthy monologue about whatever it is you’ve been dying to get off your chest, even defective silicone implants, you JavaStrippers. Or would that be a lengthy mamologue? Oops, we seem to be giving away the answer to the high-or-not-high question here. A thousand pardons . . .

function alerting(){b="start";a="make a long string using a for loop and some numbers converted to strings, and concatenated strings";

for(i=0;i<101;i++){b=b+" " + (i*Math.random()*999).toString();}

thestring=b+"------" + a;

alert(thestring);}

If you use this method, you'll get a new document on a new page, but won't lose your current one unless you forgot how back buttons work.

function documentwrite(){document.write("See? You've written a new page. (Press BACK button.)");}