HTML Forms

If you have been searching on the Internet then there is a very good chance you have used HTML forms. They are the most popular way of gathering information from the user (client) and sending it to the server.

If you want to see a form in action just go to google.com and enter a something into the search box. That is a form.

So how we go about creating one of these then? Well as with everything in HTML it is all about tags:

 

<form action= method=”get”>

<input type=”text” name=”q”>

<input type=”submit”>

</form>

The code above, if placed inside a HTML documents BODY tag, will create a simple form like the one below:

Exercise 1.

  1. Type in the above code in a new HTML document, save it as form1.htm
  2. Opening it in a browser, does it look like the screenshot above?
  3. Type something in the box and click the submit button. What happens?

Here is a break down of what all the different parts do:

Join now!

Basic Form Inputs

Text Boxes

<input type=”text” name=”text1” maxlength=”100”>

<input type=”text” name=”text2”>

<input type=”text” name=”text3” value=”Enter some text here”>

Password Boxes (hide the users input)

<input type=”password” name=”password1”>

Select Boxes (combo boxes)

<select name=”combo1”>

<option value=”Number1”>One</option>

<option value=”Number2” selected>Two</option>

<option value=”Number3”>Three</option>

</select>

Note the selected property in the second option tag tells the browser that this option should be the one selected as default when the page first loads.


Exercise 2.

  1. Save your HTML file as form2.htm
  2. Remove the text field code from the ...

This is a preview of the whole essay