SHARE
Facebook X Pinterest WhatsApp

HTML Goodies: Script Tip: Week 22

Written By
thumbnail
Joe Burns
Joe Burns
Jan 4, 2005


La Tipa…

Last week you got the rundown on how this guestbook script works and since there’s no good starting point for tearing this one apart, we’ll just start from the top down. First we grab the user’s name and e-mail address and stick them in the subject line of the FORM flag.

Just in case you’re a little forgetful, here’s the script and its effect once again.


See the Guestbook in Action

Here’s the Code for the Guestbook

The guestbook was written as two separate scripts. It didn’t have to be, but at my age, you want to make a point of keeping everything straight in your aging gray matter. So, I set the prompts apart in a script of their own. It looks like this:


<SCRIPT LANGUAGE=”javascript”>

var name = prompt
(“What is your name?”,”Write It Here”)
var email = prompt
(“What is your email address”, “Write It Here”)

</SCRIPT>


The prompt format is pretty simple and should be familiar to you by now. A variable name is assigned by writing “var” then the variable name. In this case we used “name” for the text string the user enters for his or her name and “e-mail” to represent the text string the user puts in representing his or her e-mail address.

Use the prompt format by including the command “prompt” followed by two sets of text in parentheses. The first set of text will appear in the box itself and the second will appear in the text box on the prompt box.

Okay, so now we have these two text strings and we can place them just about anywhere by calling for them by their variable name.

The Main FORM Flag

It looks like this:


<FORM METHOD=’post’ ACTION=’mailto:jburns@htmlgoodies.com?Subject=Script Tip mail from ” +name+ ” at ” +email+ “‘ ENCTYPE=’text/plain’ NAME=’gbookForm’>


Please understand that the line above should all go on one long line. It is only broken into pieces because of page constraints.

So, what do we have? It’s a basic mailto: FORM setup. We have the METHOD set to post and the action set to send the e-mail to my e-mail box. But look at the “Subject=” section:

Subject=Script Tip mail from ” +name+ ” at ” +email+ “‘

We’re actually using the two variable names taken from the prompts to build the subject line. When the e-mail arrives in your box, it will read that there is “Script Tip mail from Name at E-mail Address“.

Notice the double quotes and the plus signs. See how the plus signs sit on either side of the variable names? That signifies that this is not text to be written, but rather a variable string to be returned. Also notice the spaces left on either side of ” at “. Without those spaces, the text string would just butt right up against the text in double quotes. You leave the spaces in to make it readable.

The FORM flag then runs out, setting the ENCTYPE to “text/plain” and naming the entire form ‘gbookForm’.

Next Week: The HTML Form Elements


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.