Home arrow HTML arrow Page 3 - Finding Values and More with Web Page Dialog Boxes
HTML

Finding Values and More with Web Page Dialog Boxes


In this conclusion to a five-part series, we'll wrap up our discussion of what you can do with web page dialog boxes. Among other things, we include some tips you'll need to keep in mind when you include web page dialog boxes in your commercial projects.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
January 26, 2009
TABLE OF CONTENTS:
  1. · Finding Values and More with Web Page Dialog Boxes
  2. · Easy Way of Creating Descendant Dialog Boxes
  3. · Developing the String
  4. · Commercial Project

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Finding Values and More with Web Page Dialog Boxes - Developing the String
(Page 3 of 4 )

To develop the string for a dialog box, first write out the complete HTML code for the dialog box. Next, with the back slash, escape all the signs such as ‘<’, ‘>’, ‘(‘, and ‘{‘ that need to be escaped. Finally, put quotes around the string and assign it to a variable (boxStr1).

The following is an example of a string for the first dialog box:


boxStr1 = "<html>"

+ "<head>"

+ "<title>"

+ "First Dialog Box"

+ "</title>"

+ "<style type="text/css">"

+ "body {background-color:silver}"

+ "</style>"

+ "<script type="text/javascript">"

+ "function sendRefBack()"

+ "{"

+ "return window.opener.sendRefBack();"

+ "}"

+ "function openAnotherBox()"

+ "{"

+ "mainPageRef = sendRefBack();"

+ "contentStr = mainPageRef.boxStr2;"

+ "myRef = window.open("","box2","menubar=no,toolbar=no,width=400,height=400","");"

+ "myRef.document.write(contentStr);"

+ "}"

+ "</script>"

+ "<body>"

+ "First Input: &nbsp&nbsp&nbsp&nbsp&nbsp<input type="text"> <br />"

+ "Second Input: <input type="text"> <br /> <br />"

+ "<button type="button" onclick="openAnotherBox()">Open Another Box</button> <br /> <br />"

+ "<button type="button">Done</button>"

+ "</body>"

+ "</html>";


If you have three dialog boxes, you need three strings like this in the main window. You need one string for each dialog box. You normally do not need more than three dialog boxes in addition to the main window. Of course, the dialog boxes can have different HTML content.

If you look at the above box string you will notice that it has two functions in the JavaScript. There are also two text input controls and two buttons in the BODY element. I will talk about the two functions. You need at least these two functions in each of your dialog boxes.

I start with the first one:


function sendRefBack()

{

return window.opener.sendRefBack();

}


This function is in every dialog box except the last. It simple calls the same function that is in the immediate parent’s box. The aim is to ultimately get the reference of the main window at the calling window (function). This function, as we saw above, in the main window, determines the reference of the main window and returns it.

The other function that should be in every dialog box except the last is:


function openAnotherBox()

{

mainPageRef = sendRefBack();

contentStr = mainPageRef.boxStr2;

myRef = window.open("","box2","menubar=no,toolbar=no,width=400,height=400","");

myRef.document.write(contentStr);

}


This function is called when you click the button to open a new dialog box. This function first calls the sendRefBack() function in the JavaScript of its own window. We already know that the sendRefBack() function will call the same function in the previous window. The openAnotherBox() in the calling window ultimately receives the reference to the main window and assigns it to the mainPageRef variable. The next line uses this reference to get the string for the next (child) dialog box; it assigns the string to the contentStr variable. The line after that opens a new box and assigns the resulting reference to the myRef variable. The last line uses the contentStr string, which has the content of the newly opened dialog box and writes the content to the opened box.

So the above two functions or any two functions with similar effects should be in every dialog box, except the main window and the last box. The main window should, however, have the first function modified.

I carried out a very simple project, which had a main window and three dialog boxes. The main window is as shown above; the first dialog box is also as shown above. The string for the second dialog box is shown below:


boxStr2 = "<html>"

+ "<head>"

+ "<title>"

+ "Second Dialog Box"

+ "</title>"

+ "<style type="text/css">"

+ "body {background-color:silver}"

+ "</style>"

+ "<script type="text/javascript">"

+ "function sendRefBack()"

+ "{"

+ " return window.opener.sendRefBack();"

+ "}"

+ "function openAnotherBox()"

+ "{"

+ "mainPageRef = sendRefBack();"

+ "contentStr = mainPageRef.boxStr3;"

+ "myRef = window.open("","box3","menubar=no,toolbar=no,width=400,height=400","");"

+ "myRef.document.write(contentStr);"

+ "}"

+ "</script>"

+ "<body>"

+ "Input: &nbsp&nbsp&nbsp&nbsp&nbsp<input type="text"> <br /><br />"

+ "<button type="button" onclick="openAnotherBox()">Open Another Box</button> <br /> <br />"

+ "<button type="button">Done</button>"

+ "</body>"

+ "</html>";


This dialog box has one input text control and two buttons. Note that the two functions that I mentioned before are there. This window, like the previous one, can open another window. The string for the window it opens, which is the last in the chain, is as follows:


boxStr3 = "<html>"

+ "<head>"

+ "<title>"

+ "Third Dialog Box"

+ "</title>"

+ "<style type="text/css">"

+ "body {background-color:silver}"

+ "</style>"

+ "<body>"

+ "This is some confirmation text. If you agree click OK, else click Cancel<br /><br />"

+ "<button type="button">OK</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

+ "<button type="button">Cancel</button>"

+ "</body>"

+ "</html>";


This window does not have JavaScript. It does not have the two functions we have been talking about.

You can use all the code in this section as the basis for your own project.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials