SHARE
Facebook X Pinterest WhatsApp

HTML Goodies: Script Tip: Week 24

Written By
thumbnail
Joe Burns
Joe Burns
Jan 4, 2005


Thy Name is Tip…

Okay, we understand the top, the prompts, and we understand the bottom, the HTML form flags. Now let’s hit the guts of this script. The function.


See the Guestbook in Action

Here’s the Code for the Guestbook

The function looks like this:

<SCRIPT LANGUAGE=”javascript”>

function verify()
{
var OpenWindow=window.open(“”, “newwin”, “height=300,width=300”);
OpenWindow.document.write(“<HTML>”)
OpenWindow.document.write(“<TITLE>Thanks for Writing</TITLE>”)
OpenWindow.document.write(“<BODY BGCOLOR=’ffffcc’>”)
OpenWindow.document.write(“<CENTER>”)
OpenWindow.document.write(“Thank you <B>” + name + “</B> from <B>” +email+ “</B><P>”)
OpenWindow.document.write(“Your message <P><I>” + document.gbookForm.maintext.value + “</I><P>”)
OpenWindow.document.write(“from ” + name + ” / ” +email+ “<P>”)
OpenWindow.document.write(“will be sent along when you close this window.<P>”)
OpenWindow.document.write(“<CENTER>”)
OpenWindow.document.write(“<FORM><INPUT TYPE=’button’ VALUE=’Close Window’ onClick=’self.close()’></FORM>”)
OpenWindow.document.write(“</CENTER>”)
OpenWindow.document.write(“</HTML>”)
}
</SCRIPT>

If you’re an avid reader of HTML Goodies, then you probably recognize the format. The function, named verify(), is surrounding JavaScript that will open a new window and fill it with text. I have an entire tutorial on just that right here.

The function is called for when you click on the HTML form button. Remember that onClick=”verify()”?

Once clicked, the variable “OpenWindow” is assigned the properties of the new window. Then, one after the other, lines of HTML are filled in. But to get the effect that the HTML page that is being filled in was created from the e-mail, we start to use the text strings that we gathered from the two prompts, namely “name” and “e-mail.” Look at this line:

OpenWindow.document.write(“Thank you <B>” + name + “</B> from <B>” +email+ “</B><P>”)

See how the text strings are being placed to give the effect that the window was opened just for the user? Then this line of code:

OpenWindow.document.write(“Your message <P><I>” + document.gbookForm.maintext.value + “</I><P>”)

…grabs the text the user wrote into the TEXTAREA box and displays it. And it is the display, I think, that makes this little window come alive. See how the first time the name and e-mail are displayed they’re in bold and the text from the TEXTAREA box is italic? I think that really looks great. It gives the impression that the little window is a form created off of the e-mail itself rather than a simple representation of the information given to the computer.

Then this line of code:

OpenWindow.document.write(“<FORM><INPUT TYPE=’button’ VALUE=’Close Window’ onClick=’self.close()’></FORM>”)

…creates a great button that closes the window. The “self.close” object.method statement does the trick. Great effect.

Finally, the ending HTML commands are written to the page and the function is closed.

And another script comes to an end. Feel free to use the script just as it is or add or take away as you see fit. Some people like the prompts, some don’t. It’s up to you. I happen to like them.

Since we’re done with this one, let’s get back to the that running digital clock. I fixed it!

Next Week: The Digital Clock Revisited


Learn to write your own JavaScripts with the
JavaScript Goodies!

You can find many other uses for JavaScript
on your Web pages here!

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.