Advanced HTML forms

In 'Introduction to HTML Forms', we investigated input types and essential form elements. First we introduced the script required to start your forms, then we investigated commonly used input types such as text, password, checkbox and radio.

We shall now delve into advanced form elements such as drop-down menus (represented by the select command), rich text fields (represented by the textarea command), and the submit and reset buttons used to post your form data.

It is essential to reiterate the importance of including the 'name' property within all form elements. The name and associated value is what allows the data to be correctly e-mailed to the recipient.

The Select Command

Select allows the user to choose a value from a list of options in either a drop-down or a scroll-down menu format.

<select name="housing" size="3">
  <option value="rent">Renting</option>
  <option value="own">Own your own home</option>
  <option value="share" selected >Sharing</option>
</select>

This displays a box with three options: Renting, Own your own home and Sharing. The latter will be pre-selected due to the inclusion of 'selected' in the option command. If there were several other available options, you would include that number of OPTION values between the select and /select commands.

The Size Property

If you remove the size property, a default of size="1" is enforced. This creates a drop-down menu in its traditional format, that is, one choice is displayed, with other options available by pressing the arrow button on the right of the menu.

Similarly, if there were several alternatives and the coded size value was 3, three options would be visible at a time, and the viewer would need to scroll up or down to see more.

The Multiple Property

By default, you can only choose one option at a time; however, by including 'multiple' in your opening select command, a user can choose many options by holding down the <Shift> key when selecting. For example:

<select name="housing" size="3" multiple>

The Textarea Command

Often, forms have large boxes for inserting general comments. Logically, one could assume that this is a text input type with varied sizing values. However, this is not the case.

Apart from displaying a larger entry space than a usual text input type, textarea represents a Rich Text Field. In other words, a space for data that may not be just normal text. Rich Text Fields may (if coded appropriately) allow the user to include graphics, special characters, and even HTML code.

This extension is often unused - however, because of this potential, input type="text" won't suffice. Therefore, we use textarea:
<textarea name="Comments" rows="3" cols="30">Enter comments here</textarea>

The open textarea command lets the computer know we are creating a rich text field. This is followed by the essential 'name' value mentioned earlier. Following this there are two properties, rows and cols. 'Rows' determines how deep the box will be while 'cols' presets its width. The units of measurement for the latter is the number of characters, so in the above example, the box would be 30 characters across and three rows deep.

The text between the opening command and the closing </textarea> is optional. If included, this text is displayed within the box as a prompt. If left blank, the box will be empty.

The Submit And Reset Buttons

Creating the submit and reset buttons is the easiest part of coding forms, provided your opening form command is correct. Their format is:

<input type="submit" value="Send Form">
<input type="reset" value="Reset Values">

Input type="submit" causes the computer to automatically create a button with "Send Form" on it, and then to send all form data to the e-mail address specified in the opening form command when the button is clicked.

When the computer sees input type="reset", it similarly creates a button with the text 'Reset Values', and returns all items to their default values when clicked.

If you omit the value properties, the submit button will automatically read 'Submit Query' and the reset button will simply say 'Reset'.

Join the PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Heidi Woof

PC World
Show Comments

Essentials

Lexar® JumpDrive® S57 USB 3.0 flash drive

Learn more >

Microsoft L5V-00027 Sculpt Ergonomic Keyboard Desktop

Learn more >

Mobile

Lexar® JumpDrive® S45 USB 3.0 flash drive 

Learn more >

Exec

Lexar® Professional 1800x microSDHC™/microSDXC™ UHS-II cards 

Learn more >

Audio-Technica ATH-ANC70 Noise Cancelling Headphones

Learn more >

Lexar® JumpDrive® C20c USB Type-C flash drive 

Learn more >

HD Pan/Tilt Wi-Fi Camera with Night Vision NC450

Learn more >

Budget

Back To Business Guide

Click for more ›

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?